let Z = navigator.userAgent, _r = navigator.platform, we = /gecko\/\d/i.test(Z), Xr = /MSIE \d/.test(Z), $r = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Z), ki = /Edge\/(\d+)/.exec(Z), N = Xr || $r || ki, F = N && (Xr ? document.documentMode || 6 : +(ki || $r)[1]), $ = !ki && /WebKit\//.test(Z), Ss = $ && /Qt\/\d+\.\d+/.test(Z), Ti = !ki && /Chrome\//.test(Z), fe = /Opera\//.test(Z), Mi = /Apple Computer/.test(navigator.vendor), Ls = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(Z), ks = /PhantomJS/.test(Z), Qt = Mi && (/Mobile\/\w+/.test(Z) || navigator.maxTouchPoints > 2), Ni = /Android/.test(Z), It = Qt || Ni || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(Z), ne = Qt || /Mac/.test(_r), Ts = /\bCrOS\b/.test(Z), Ms = /win/i.test(_r), Re = fe && Z.match(/Version\/(\d*\.\d*)/);
Re && (Re = Number(Re[1]));
Re && Re >= 15 && (fe = !1, $ = !0);
let lr = ne && (Ss || fe && (Re == null || Re < 12.11)), gl = we || N && F >= 9;
function ut(e) {
  return new RegExp("(^|\\s)" + e + "(?:$|\\s)\\s*");
}
let Xe = function(e, t) {
  let i = e.className, l = ut(t).exec(i);
  if (l) {
    let r = i.slice(l.index + l[0].length);
    e.className = i.slice(0, l.index) + (r ? l[1] + r : "");
  }
};
function Ne(e) {
  for (let t = e.childNodes.length; t > 0; --t)
    e.removeChild(e.firstChild);
  return e;
}
function ie(e, t) {
  return Ne(e).appendChild(t);
}
function C(e, t, i, l) {
  let r = document.createElement(e);
  if (i && (r.className = i), l && (r.style.cssText = l), typeof t == "string")
    r.appendChild(document.createTextNode(t));
  else if (t)
    for (let n = 0; n < t.length; ++n)
      r.appendChild(t[n]);
  return r;
}
function rt(e, t, i, l) {
  let r = C(e, t, i, l);
  return r.setAttribute("role", "presentation"), r;
}
let Ge;
document.createRange ? Ge = function(e, t, i, l) {
  let r = document.createRange();
  return r.setEnd(l || e, i), r.setStart(e, t), r;
} : Ge = function(e, t, i) {
  let l = document.body.createTextRange();
  try {
    l.moveToElementText(e.parentNode);
  } catch {
    return l;
  }
  return l.collapse(!0), l.moveEnd("character", i), l.moveStart("character", t), l;
};
function Ae(e, t) {
  if (t.nodeType == 3 && (t = t.parentNode), e.contains)
    return e.contains(t);
  do
    if (t.nodeType == 11 && (t = t.host), t == e)
      return !0;
  while (t = t.parentNode);
}
function re() {
  let e;
  try {
    e = document.activeElement;
  } catch {
    e = document.body || null;
  }
  for (; e && e.shadowRoot && e.shadowRoot.activeElement; )
    e = e.shadowRoot.activeElement;
  return e;
}
function $e(e, t) {
  let i = e.className;
  ut(t).test(i) || (e.className += (i ? " " : "") + t);
}
function _i(e, t) {
  let i = e.split(" ");
  for (let l = 0; l < i.length; l++)
    i[l] && !ut(i[l]).test(t) && (t += " " + i[l]);
  return t;
}
let Rt = function(e) {
  e.select();
};
Qt ? Rt = function(e) {
  e.selectionStart = 0, e.selectionEnd = e.value.length;
} : N && (Rt = function(e) {
  try {
    e.select();
  } catch {
  }
});
function yl(e) {
  let t = Array.prototype.slice.call(arguments, 1);
  return function() {
    return e.apply(null, t);
  };
}
function Ue(e, t, i) {
  t || (t = {});
  for (let l in e)
    e.hasOwnProperty(l) && (i !== !1 || !t.hasOwnProperty(l)) && (t[l] = e[l]);
  return t;
}
function le(e, t, i, l, r) {
  t == null && (t = e.search(/[^\s\u00a0]/), t == -1 && (t = e.length));
  for (let n = l || 0, s = r || 0; ; ) {
    let o = e.indexOf("	", n);
    if (o < 0 || o >= t)
      return s + (t - n);
    s += o - n, s += i - s % i, n = o + 1;
  }
}
class ft {
  constructor() {
    this.id = null, this.f = null, this.time = 0, this.handler = yl(this.onTimeout, this);
  }
  onTimeout(t) {
    t.id = 0, t.time <= +/* @__PURE__ */ new Date() ? t.f() : setTimeout(t.handler, t.time - +/* @__PURE__ */ new Date());
  }
  set(t, i) {
    this.f = i;
    const l = +/* @__PURE__ */ new Date() + t;
    (!this.id || l < this.time) && (clearTimeout(this.id), this.id = setTimeout(this.handler, t), this.time = l);
  }
}
function K(e, t) {
  for (let i = 0; i < e.length; ++i)
    if (e[i] == t)
      return i;
  return -1;
}
let Yr = 50, Ai = { toString: function() {
  return "CodeMirror.Pass";
} }, ce = { scroll: !1 }, Xi = { origin: "*mouse" }, At = { origin: "+move" };
function Qi(e, t, i) {
  for (let l = 0, r = 0; ; ) {
    let n = e.indexOf("	", l);
    n == -1 && (n = e.length);
    let s = n - l;
    if (n == e.length || r + s >= t)
      return l + Math.min(s, t - r);
    if (r += n - l, r += i - r % i, l = n + 1, r >= t)
      return l;
  }
}
let li = [""];
function ml(e) {
  for (; li.length <= e; )
    li.push(O(li) + " ");
  return li[e];
}
function O(e) {
  return e[e.length - 1];
}
function Di(e, t) {
  let i = [];
  for (let l = 0; l < e.length; l++)
    i[l] = t(e[l], l);
  return i;
}
function Ns(e, t, i) {
  let l = 0, r = i(t);
  for (; l < e.length && i(e[l]) <= r; )
    l++;
  e.splice(l, 0, t);
}
function rr() {
}
function jr(e, t) {
  let i;
  return Object.create ? i = Object.create(e) : (rr.prototype = e, i = new rr()), t && Ue(t, i), i;
}
let As = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
function Ji(e) {
  return /\w/.test(e) || e > "" && (e.toUpperCase() != e.toLowerCase() || As.test(e));
}
function ui(e, t) {
  return t ? t.source.indexOf("\\w") > -1 && Ji(e) ? !0 : t.test(e) : Ji(e);
}
function nr(e) {
  for (let t in e)
    if (e.hasOwnProperty(t) && e[t])
      return !1;
  return !0;
}
let Ds = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
function Vi(e) {
  return e.charCodeAt(0) >= 768 && Ds.test(e);
}
function qr(e, t, i) {
  for (; (i < 0 ? t > 0 : t < e.length) && Vi(e.charAt(t)); )
    t += i;
  return t;
}
function Bt(e, t, i) {
  let l = t > i ? -1 : 1;
  for (; ; ) {
    if (t == i)
      return t;
    let r = (t + i) / 2, n = l < 0 ? Math.ceil(r) : Math.floor(r);
    if (n == t)
      return e(n) ? t : i;
    e(n) ? i = n : t = n + l;
  }
}
function Os(e, t, i, l) {
  if (!e)
    return l(t, i, "ltr", 0);
  let r = !1;
  for (let n = 0; n < e.length; ++n) {
    let s = e[n];
    (s.from < i && s.to > t || t == i && s.to == t) && (l(Math.max(s.from, t), Math.min(s.to, i), s.level == 1 ? "rtl" : "ltr", n), r = !0);
  }
  r || l(t, i, "ltr");
}
let Tt = null;
function zt(e, t, i) {
  let l;
  Tt = null;
  for (let r = 0; r < e.length; ++r) {
    let n = e[r];
    if (n.from < t && n.to > t)
      return r;
    n.to == t && (n.from != n.to && i == "before" ? l = r : Tt = r), n.from == t && (n.from != n.to && i != "before" ? l = r : Tt = r);
  }
  return l != null ? l : Tt;
}
let Ws = function() {
  let e = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN", t = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
  function i(u) {
    return u <= 247 ? e.charAt(u) : 1424 <= u && u <= 1524 ? "R" : 1536 <= u && u <= 1785 ? t.charAt(u - 1536) : 1774 <= u && u <= 2220 ? "r" : 8192 <= u && u <= 8203 ? "w" : u == 8204 ? "b" : "L";
  }
  let l = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/, r = /[stwN]/, n = /[LRr]/, s = /[Lb1n]/, o = /[1n]/;
  function a(u, f, h) {
    this.level = u, this.from = f, this.to = h;
  }
  return function(u, f) {
    let h = f == "ltr" ? "L" : "R";
    if (u.length == 0 || f == "ltr" && !l.test(u))
      return !1;
    let d = u.length, c = [];
    for (let g = 0; g < d; ++g)
      c.push(i(u.charCodeAt(g)));
    for (let g = 0, b = h; g < d; ++g) {
      let y = c[g];
      y == "m" ? c[g] = b : b = y;
    }
    for (let g = 0, b = h; g < d; ++g) {
      let y = c[g];
      y == "1" && b == "r" ? c[g] = "n" : n.test(y) && (b = y, y == "r" && (c[g] = "R"));
    }
    for (let g = 1, b = c[0]; g < d - 1; ++g) {
      let y = c[g];
      y == "+" && b == "1" && c[g + 1] == "1" ? c[g] = "1" : y == "," && b == c[g + 1] && (b == "1" || b == "n") && (c[g] = b), b = y;
    }
    for (let g = 0; g < d; ++g) {
      let b = c[g];
      if (b == ",")
        c[g] = "N";
      else if (b == "%") {
        let y;
        for (y = g + 1; y < d && c[y] == "%"; ++y)
          ;
        let L = g && c[g - 1] == "!" || y < d && c[y] == "1" ? "1" : "N";
        for (let w = g; w < y; ++w)
          c[w] = L;
        g = y - 1;
      }
    }
    for (let g = 0, b = h; g < d; ++g) {
      let y = c[g];
      b == "L" && y == "1" ? c[g] = "L" : n.test(y) && (b = y);
    }
    for (let g = 0; g < d; ++g)
      if (r.test(c[g])) {
        let b;
        for (b = g + 1; b < d && r.test(c[b]); ++b)
          ;
        let y = (g ? c[g - 1] : h) == "L", L = (b < d ? c[b] : h) == "L", w = y == L ? y ? "L" : "R" : h;
        for (let M = g; M < b; ++M)
          c[M] = w;
        g = b - 1;
      }
    let p = [], m;
    for (let g = 0; g < d; )
      if (s.test(c[g])) {
        let b = g;
        for (++g; g < d && s.test(c[g]); ++g)
          ;
        p.push(new a(0, b, g));
      } else {
        let b = g, y = p.length, L = f == "rtl" ? 1 : 0;
        for (++g; g < d && c[g] != "L"; ++g)
          ;
        for (let w = b; w < g; )
          if (o.test(c[w])) {
            b < w && (p.splice(y, 0, new a(1, b, w)), y += L);
            let M = w;
            for (++w; w < g && o.test(c[w]); ++w)
              ;
            p.splice(y, 0, new a(2, M, w)), y += L, b = w;
          } else
            ++w;
        b < g && p.splice(y, 0, new a(1, b, g));
      }
    return f == "ltr" && (p[0].level == 1 && (m = u.match(/^\s+/)) && (p[0].from = m[0].length, p.unshift(new a(0, 0, m[0].length))), O(p).level == 1 && (m = u.match(/\s+$/)) && (O(p).to -= m[0].length, p.push(new a(0, d - m[0].length, d)))), f == "rtl" ? p.reverse() : p;
  };
}();
function Le(e, t) {
  let i = e.order;
  return i == null && (i = e.order = Ws(e.text, t)), i;
}
const Zr = [];
let S = function(e, t, i) {
  if (e.addEventListener)
    e.addEventListener(t, i, !1);
  else if (e.attachEvent)
    e.attachEvent("on" + t, i);
  else {
    let l = e._handlers || (e._handlers = {});
    l[t] = (l[t] || Zr).concat(i);
  }
};
function bl(e, t) {
  return e._handlers && e._handlers[t] || Zr;
}
function te(e, t, i) {
  if (e.removeEventListener)
    e.removeEventListener(t, i, !1);
  else if (e.detachEvent)
    e.detachEvent("on" + t, i);
  else {
    let l = e._handlers, r = l && l[t];
    if (r) {
      let n = K(r, i);
      n > -1 && (l[t] = r.slice(0, n).concat(r.slice(n + 1)));
    }
  }
}
function E(e, t) {
  let i = bl(e, t);
  if (!i.length)
    return;
  let l = Array.prototype.slice.call(arguments, 2);
  for (let r = 0; r < i.length; ++r)
    i[r].apply(null, l);
}
function R(e, t, i) {
  return typeof t == "string" && (t = { type: t, preventDefault: function() {
    this.defaultPrevented = !0;
  } }), E(e, i || t.type, e, t), el(t) || t.codemirrorIgnore;
}
function Qr(e) {
  let t = e._handlers && e._handlers.cursorActivity;
  if (!t)
    return;
  let i = e.curOp.cursorActivityHandlers || (e.curOp.cursorActivityHandlers = []);
  for (let l = 0; l < t.length; ++l)
    K(i, t[l]) == -1 && i.push(t[l]);
}
function se(e, t) {
  return bl(e, t).length > 0;
}
function gt(e) {
  e.prototype.on = function(t, i) {
    S(this, t, i);
  }, e.prototype.off = function(t, i) {
    te(this, t, i);
  };
}
function j(e) {
  e.preventDefault ? e.preventDefault() : e.returnValue = !1;
}
function Jr(e) {
  e.stopPropagation ? e.stopPropagation() : e.cancelBubble = !0;
}
function el(e) {
  return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == !1;
}
function Gt(e) {
  j(e), Jr(e);
}
function xl(e) {
  return e.target || e.srcElement;
}
function Vr(e) {
  let t = e.which;
  return t == null && (e.button & 1 ? t = 1 : e.button & 2 ? t = 3 : e.button & 4 && (t = 2)), ne && e.ctrlKey && t == 1 && (t = 3), t;
}
let Hs = function() {
  if (N && F < 9)
    return !1;
  let e = C("div");
  return "draggable" in e || "dragDrop" in e;
}(), $i;
function Fs(e) {
  if ($i == null) {
    let i = C("span", "​");
    ie(e, C("span", [i, document.createTextNode("x")])), e.firstChild.offsetHeight != 0 && ($i = i.offsetWidth <= 1 && i.offsetHeight > 2 && !(N && F < 8));
  }
  let t = $i ? C("span", "​") : C("span", " ", null, "display: inline-block; width: 1px; margin-right: -1px");
  return t.setAttribute("cm-text", ""), t;
}
let Yi;
function Ps(e) {
  if (Yi != null)
    return Yi;
  let t = ie(e, document.createTextNode("AخA")), i = Ge(t, 0, 1).getBoundingClientRect(), l = Ge(t, 1, 2).getBoundingClientRect();
  return Ne(e), !i || i.left == i.right ? !1 : Yi = l.right - i.right < 3;
}
let wl = `

b`.split(/\n/).length != 3 ? (e) => {
  let t = 0, i = [], l = e.length;
  for (; t <= l; ) {
    let r = e.indexOf(`
`, t);
    r == -1 && (r = e.length);
    let n = e.slice(t, e.charAt(r - 1) == "\r" ? r - 1 : r), s = n.indexOf("\r");
    s != -1 ? (i.push(n.slice(0, s)), t += s + 1) : (i.push(n), t = r + 1);
  }
  return i;
} : (e) => e.split(/\r\n?|\n/), Es = window.getSelection ? (e) => {
  try {
    return e.selectionStart != e.selectionEnd;
  } catch {
    return !1;
  }
} : (e) => {
  let t;
  try {
    t = e.ownerDocument.selection.createRange();
  } catch {
  }
  return !t || t.parentElement() != e ? !1 : t.compareEndPoints("StartToEnd", t) != 0;
}, Is = (() => {
  let e = C("div");
  return "oncopy" in e ? !0 : (e.setAttribute("oncopy", "return;"), typeof e.oncopy == "function");
})(), ji = null;
function Rs(e) {
  if (ji != null)
    return ji;
  let t = ie(e, C("span", "x")), i = t.getBoundingClientRect(), l = Ge(t, 0, 1).getBoundingClientRect();
  return ji = Math.abs(i.left - l.left) > 1;
}
let vl = {}, tt = {};
function Bs(e, t) {
  arguments.length > 2 && (t.dependencies = Array.prototype.slice.call(arguments, 2)), vl[e] = t;
}
function zs(e, t) {
  tt[e] = t;
}
function pi(e) {
  if (typeof e == "string" && tt.hasOwnProperty(e))
    e = tt[e];
  else if (e && typeof e.name == "string" && tt.hasOwnProperty(e.name)) {
    let t = tt[e.name];
    typeof t == "string" && (t = { name: t }), e = jr(t, e), e.name = t.name;
  } else {
    if (typeof e == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(e))
      return pi("application/xml");
    if (typeof e == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(e))
      return pi("application/json");
  }
  return typeof e == "string" ? { name: e } : e || { name: "null" };
}
function Cl(e, t) {
  t = pi(t);
  let i = vl[t.name];
  if (!i)
    return Cl(e, "text/plain");
  let l = i(e, t);
  if (nt.hasOwnProperty(t.name)) {
    let r = nt[t.name];
    for (let n in r)
      r.hasOwnProperty(n) && (l.hasOwnProperty(n) && (l["_" + n] = l[n]), l[n] = r[n]);
  }
  if (l.name = t.name, t.helperType && (l.helperType = t.helperType), t.modeProps)
    for (let r in t.modeProps)
      l[r] = t.modeProps[r];
  return l;
}
let nt = {};
function Gs(e, t) {
  let i = nt.hasOwnProperty(e) ? nt[e] : nt[e] = {};
  Ue(t, i);
}
function Be(e, t) {
  if (t === !0)
    return t;
  if (e.copyState)
    return e.copyState(t);
  let i = {};
  for (let l in t) {
    let r = t[l];
    r instanceof Array && (r = r.concat([])), i[l] = r;
  }
  return i;
}
function Sl(e, t) {
  let i;
  for (; e.innerMode && (i = e.innerMode(t), !(!i || i.mode == e)); )
    t = i.state, e = i.mode;
  return i || { mode: e, state: t };
}
function en(e, t, i) {
  return e.startState ? e.startState(t, i) : !0;
}
class Oi {
  constructor(t, i, l) {
    this.pos = this.start = 0, this.string = t, this.tabSize = i || 8, this.lastColumnPos = this.lastColumnValue = 0, this.lineStart = 0, this.lineOracle = l;
  }
  eol() {
    return this.pos >= this.string.length;
  }
  sol() {
    return this.pos == this.lineStart;
  }
  peek() {
    return this.string.charAt(this.pos) || void 0;
  }
  next() {
    if (this.pos < this.string.length)
      return this.string.charAt(this.pos++);
  }
  eat(t) {
    let i = this.string.charAt(this.pos), l;
    if (typeof t == "string" ? l = i == t : l = i && (t.test ? t.test(i) : t(i)), l)
      return ++this.pos, i;
  }
  eatWhile(t) {
    let i = this.pos;
    for (; this.eat(t); )
      ;
    return this.pos > i;
  }
  eatSpace() {
    let t = this.pos;
    for (; /[\s\u00a0]/.test(this.string.charAt(this.pos)); )
      ++this.pos;
    return this.pos > t;
  }
  skipToEnd() {
    this.pos = this.string.length;
  }
  skipTo(t) {
    let i = this.string.indexOf(t, this.pos);
    if (i > -1)
      return this.pos = i, !0;
  }
  backUp(t) {
    this.pos -= t;
  }
  column() {
    return this.lastColumnPos < this.start && (this.lastColumnValue = le(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue), this.lastColumnPos = this.start), this.lastColumnValue - (this.lineStart ? le(this.string, this.lineStart, this.tabSize) : 0);
  }
  indentation() {
    return le(this.string, null, this.tabSize) - (this.lineStart ? le(this.string, this.lineStart, this.tabSize) : 0);
  }
  match(t, i, l) {
    if (typeof t == "string") {
      let r = (s) => l ? s.toLowerCase() : s, n = this.string.substr(this.pos, t.length);
      if (r(n) == r(t))
        return i !== !1 && (this.pos += t.length), !0;
    } else {
      let r = this.string.slice(this.pos).match(t);
      return r && r.index > 0 ? null : (r && i !== !1 && (this.pos += r[0].length), r);
    }
  }
  current() {
    return this.string.slice(this.start, this.pos);
  }
  hideFirstChars(t, i) {
    this.lineStart += t;
    try {
      return i();
    } finally {
      this.lineStart -= t;
    }
  }
  lookAhead(t) {
    let i = this.lineOracle;
    return i && i.lookAhead(t);
  }
  baseToken() {
    let t = this.lineOracle;
    return t && t.baseToken(this.pos);
  }
}
function v(e, t) {
  if (t -= e.first, t < 0 || t >= e.size)
    throw new Error("There is no line " + (t + e.first) + " in the document.");
  let i = e;
  for (; !i.lines; )
    for (let l = 0; ; ++l) {
      let r = i.children[l], n = r.chunkSize();
      if (t < n) {
        i = r;
        break;
      }
      t -= n;
    }
  return i.lines[t];
}
function ze(e, t, i) {
  let l = [], r = t.line;
  return e.iter(t.line, i.line + 1, (n) => {
    let s = n.text;
    r == i.line && (s = s.slice(0, i.ch)), r == t.line && (s = s.slice(t.ch)), l.push(s), ++r;
  }), l;
}
function qi(e, t, i) {
  let l = [];
  return e.iter(t, i, (r) => {
    l.push(r.text);
  }), l;
}
function pe(e, t) {
  let i = t - e.height;
  if (i)
    for (let l = e; l; l = l.parent)
      l.height += i;
}
function W(e) {
  if (e.parent == null)
    return null;
  let t = e.parent, i = K(t.lines, e);
  for (let l = t.parent; l; t = l, l = l.parent)
    for (let r = 0; l.children[r] != t; ++r)
      i += l.children[r].chunkSize();
  return i + t.first;
}
function Ie(e, t) {
  let i = e.first;
  e:
    do {
      for (let r = 0; r < e.children.length; ++r) {
        let n = e.children[r], s = n.height;
        if (t < s) {
          e = n;
          continue e;
        }
        t -= s, i += n.chunkSize();
      }
      return i;
    } while (!e.lines);
  let l = 0;
  for (; l < e.lines.length; ++l) {
    let r = e.lines[l], n = r.height;
    if (t < n)
      break;
    t -= n;
  }
  return i + l;
}
function Ut(e, t) {
  return t >= e.first && t < e.first + e.size;
}
function Ll(e, t) {
  return String(e.lineNumberFormatter(t + e.firstLineNumber));
}
function x(e, t, i = null) {
  if (!(this instanceof x))
    return new x(e, t, i);
  this.line = e, this.ch = t, this.sticky = i;
}
function T(e, t) {
  return e.line - t.line || e.ch - t.ch;
}
function tl(e, t) {
  return e.sticky == t.sticky && T(e, t) == 0;
}
function il(e) {
  return x(e.line, e.ch);
}
function Wi(e, t) {
  return T(e, t) < 0 ? t : e;
}
function Hi(e, t) {
  return T(e, t) < 0 ? e : t;
}
function tn(e, t) {
  return Math.max(e.first, Math.min(t, e.first + e.size - 1));
}
function k(e, t) {
  if (t.line < e.first)
    return x(e.first, 0);
  let i = e.first + e.size - 1;
  return t.line > i ? x(i, v(e, i).text.length) : Us(t, v(e, t.line).text.length);
}
function Us(e, t) {
  let i = e.ch;
  return i == null || i > t ? x(e.line, t) : i < 0 ? x(e.line, 0) : e;
}
function sr(e, t) {
  let i = [];
  for (let l = 0; l < t.length; l++)
    i[l] = k(e, t[l]);
  return i;
}
class gi {
  constructor(t, i) {
    this.state = t, this.lookAhead = i;
  }
}
class st {
  constructor(t, i, l, r) {
    this.state = i, this.doc = t, this.line = l, this.maxLookAhead = r || 0, this.baseTokens = null, this.baseTokenPos = 1;
  }
  lookAhead(t) {
    let i = this.doc.getLine(this.line + t);
    return i != null && t > this.maxLookAhead && (this.maxLookAhead = t), i;
  }
  baseToken(t) {
    if (!this.baseTokens)
      return null;
    for (; this.baseTokens[this.baseTokenPos] <= t; )
      this.baseTokenPos += 2;
    let i = this.baseTokens[this.baseTokenPos + 1];
    return {
      type: i && i.replace(/( |^)overlay .*/, ""),
      size: this.baseTokens[this.baseTokenPos] - t
    };
  }
  nextLine() {
    this.line++, this.maxLookAhead > 0 && this.maxLookAhead--;
  }
  static fromSaved(t, i, l) {
    return i instanceof gi ? new st(t, Be(t.mode, i.state), l, i.lookAhead) : new st(t, Be(t.mode, i), l);
  }
  save(t) {
    let i = t !== !1 ? Be(this.doc.mode, this.state) : this.state;
    return this.maxLookAhead > 0 ? new gi(i, this.maxLookAhead) : i;
  }
}
function ln(e, t, i, l) {
  let r = [e.state.modeGen], n = {};
  fr(
    e,
    t.text,
    e.doc.mode,
    i,
    (o, a) => r.push(o, a),
    n,
    l
  );
  let s = i.state;
  for (let o = 0; o < e.state.overlays.length; ++o) {
    i.baseTokens = r;
    let a = e.state.overlays[o], u = 1, f = 0;
    i.state = !0, fr(e, t.text, a.mode, i, (h, d) => {
      let c = u;
      for (; f < h; ) {
        let p = r[u];
        p > h && r.splice(u, 1, h, r[u + 1], p), u += 2, f = Math.min(h, p);
      }
      if (d)
        if (a.opaque)
          r.splice(c, u - c, h, "overlay " + d), u = c + 2;
        else
          for (; c < u; c += 2) {
            let p = r[c + 1];
            r[c + 1] = (p ? p + " " : "") + "overlay " + d;
          }
    }, n), i.state = s, i.baseTokens = null, i.baseTokenPos = 1;
  }
  return { styles: r, classes: n.bgClass || n.textClass ? n : null };
}
function rn(e, t, i) {
  if (!t.styles || t.styles[0] != e.state.modeGen) {
    let l = Jt(e, W(t)), r = t.text.length > e.options.maxHighlightLength && Be(e.doc.mode, l.state), n = ln(e, t, l);
    r && (l.state = r), t.stateAfter = l.save(!r), t.styles = n.styles, n.classes ? t.styleClasses = n.classes : t.styleClasses && (t.styleClasses = null), i === e.doc.highlightFrontier && (e.doc.modeFrontier = Math.max(e.doc.modeFrontier, ++e.doc.highlightFrontier));
  }
  return t.styles;
}
function Jt(e, t, i) {
  let l = e.doc, r = e.display;
  if (!l.mode.startState)
    return new st(l, !0, t);
  let n = Ks(e, t, i), s = n > l.first && v(l, n - 1).stateAfter, o = s ? st.fromSaved(l, s, n) : new st(l, en(l.mode), n);
  return l.iter(n, t, (a) => {
    kl(e, a.text, o);
    let u = o.line;
    a.stateAfter = u == t - 1 || u % 5 == 0 || u >= r.viewFrom && u < r.viewTo ? o.save() : null, o.nextLine();
  }), i && (l.modeFrontier = o.line), o;
}
function kl(e, t, i, l) {
  let r = e.doc.mode, n = new Oi(t, e.options.tabSize, i);
  for (n.start = n.pos = l || 0, t == "" && nn(r, i.state); !n.eol(); )
    Tl(r, n, i.state), n.start = n.pos;
}
function nn(e, t) {
  if (e.blankLine)
    return e.blankLine(t);
  if (!e.innerMode)
    return;
  let i = Sl(e, t);
  if (i.mode.blankLine)
    return i.mode.blankLine(i.state);
}
function Tl(e, t, i, l) {
  for (let r = 0; r < 10; r++) {
    l && (l[0] = Sl(e, i).mode);
    let n = e.token(t, i);
    if (t.pos > t.start)
      return n;
  }
  throw new Error("Mode " + e.name + " failed to advance stream.");
}
class or {
  constructor(t, i, l) {
    this.start = t.start, this.end = t.pos, this.string = t.current(), this.type = i || null, this.state = l;
  }
}
function ar(e, t, i, l) {
  let r = e.doc, n = r.mode, s;
  t = k(r, t);
  let o = v(r, t.line), a = Jt(e, t.line, i), u = new Oi(o.text, e.options.tabSize, a), f;
  for (l && (f = []), a.state.tokenBaseArr = []; (l || u.pos < t.ch) && !u.eol(); )
    u.start = u.pos, s = Tl(n, u, a.state), l && f.push(new or(u, s, Be(r.mode, a.state)));
  return l ? f : new or(u, s, a.state);
}
function ur(e, t) {
  if (e)
    for (; ; ) {
      let i = e.match(/(?:^|\s+)line-(background-)?(\S+)/);
      if (!i)
        break;
      e = e.slice(0, i.index) + e.slice(i.index + i[0].length);
      let l = i[1] ? "bgClass" : "textClass";
      t[l] == null ? t[l] = i[2] : new RegExp("(?:^|\\s)" + i[2] + "(?:$|\\s)").test(t[l]) || (t[l] += " " + i[2]);
    }
  return e;
}
function fr(e, t, i, l, r, n, s) {
  let o = i.flattenSpans;
  o == null && (o = e.options.flattenSpans);
  let a = 0, u = null, f = new Oi(t, e.options.tabSize, l), h, d = e.options.addModeClass && [null];
  for (t == "" && ur(nn(i, l.state), n); !f.eol(); ) {
    if (f.pos > e.options.maxHighlightLength ? (o = !1, s && kl(e, t, l, f.pos), f.pos = t.length, h = null) : h = ur(Tl(i, f, l.state, d), n), d) {
      let c = d[0].name;
      c && (h = "m-" + (h ? c + " " + h : c));
    }
    if (!o || u != h) {
      for (; a < f.start; )
        a = Math.min(f.start, a + 5e3), r(a, u);
      u = h;
    }
    f.start = f.pos;
  }
  for (; a < f.pos; ) {
    let c = Math.min(f.pos, a + 5e3);
    r(c, u), a = c;
  }
}
function Ks(e, t, i) {
  let l, r, n = e.doc, s = i ? -1 : t - (e.doc.mode.innerMode ? 1e3 : 100);
  for (let o = t; o > s; --o) {
    if (o <= n.first)
      return n.first;
    let a = v(n, o - 1), u = a.stateAfter;
    if (u && (!i || o + (u instanceof gi ? u.lookAhead : 0) <= n.modeFrontier))
      return o;
    let f = le(a.text, null, e.options.tabSize);
    (r == null || l > f) && (r = o - 1, l = f);
  }
  return r;
}
function _s(e, t) {
  if (e.modeFrontier = Math.min(e.modeFrontier, t), e.highlightFrontier < t - 10)
    return;
  let i = e.first;
  for (let l = t - 1; l > i; l--) {
    let r = v(e, l).stateAfter;
    if (r && (!(r instanceof gi) || l + r.lookAhead < t)) {
      i = l + 1;
      break;
    }
  }
  e.highlightFrontier = Math.min(e.highlightFrontier, i);
}
let sn = !1, ve = !1;
function Xs() {
  sn = !0;
}
function $s() {
  ve = !0;
}
function Fi(e, t, i) {
  this.marker = e, this.from = t, this.to = i;
}
function Kt(e, t) {
  if (e)
    for (let i = 0; i < e.length; ++i) {
      let l = e[i];
      if (l.marker == t)
        return l;
    }
}
function Ys(e, t) {
  let i;
  for (let l = 0; l < e.length; ++l)
    e[l] != t && (i || (i = [])).push(e[l]);
  return i;
}
function js(e, t, i) {
  let l = i && window.WeakSet && (i.markedSpans || (i.markedSpans = /* @__PURE__ */ new WeakSet()));
  l && l.has(e.markedSpans) ? e.markedSpans.push(t) : (e.markedSpans = e.markedSpans ? e.markedSpans.concat([t]) : [t], l && l.add(e.markedSpans)), t.marker.attachLine(e);
}
function qs(e, t, i) {
  let l;
  if (e)
    for (let r = 0; r < e.length; ++r) {
      let n = e[r], s = n.marker;
      if (n.from == null || (s.inclusiveLeft ? n.from <= t : n.from < t) || n.from == t && s.type == "bookmark" && (!i || !n.marker.insertLeft)) {
        let a = n.to == null || (s.inclusiveRight ? n.to >= t : n.to > t);
        (l || (l = [])).push(new Fi(s, n.from, a ? null : n.to));
      }
    }
  return l;
}
function Zs(e, t, i) {
  let l;
  if (e)
    for (let r = 0; r < e.length; ++r) {
      let n = e[r], s = n.marker;
      if (n.to == null || (s.inclusiveRight ? n.to >= t : n.to > t) || n.from == t && s.type == "bookmark" && (!i || n.marker.insertLeft)) {
        let a = n.from == null || (s.inclusiveLeft ? n.from <= t : n.from < t);
        (l || (l = [])).push(new Fi(
          s,
          a ? null : n.from - t,
          n.to == null ? null : n.to - t
        ));
      }
    }
  return l;
}
function ll(e, t) {
  if (t.full)
    return null;
  let i = Ut(e, t.from.line) && v(e, t.from.line).markedSpans, l = Ut(e, t.to.line) && v(e, t.to.line).markedSpans;
  if (!i && !l)
    return null;
  let r = t.from.ch, n = t.to.ch, s = T(t.from, t.to) == 0, o = qs(i, r, s), a = Zs(l, n, s), u = t.text.length == 1, f = O(t.text).length + (u ? r : 0);
  if (o)
    for (let d = 0; d < o.length; ++d) {
      let c = o[d];
      if (c.to == null) {
        let p = Kt(a, c.marker);
        p ? u && (c.to = p.to == null ? null : p.to + f) : c.to = r;
      }
    }
  if (a)
    for (let d = 0; d < a.length; ++d) {
      let c = a[d];
      c.to != null && (c.to += f), c.from == null ? Kt(o, c.marker) || (c.from = f, u && (o || (o = [])).push(c)) : (c.from += f, u && (o || (o = [])).push(c));
    }
  o && (o = hr(o)), a && a != o && (a = hr(a));
  let h = [o];
  if (!u) {
    let d = t.text.length - 2, c;
    if (d > 0 && o)
      for (let p = 0; p < o.length; ++p)
        o[p].to == null && (c || (c = [])).push(new Fi(o[p].marker, null, null));
    for (let p = 0; p < d; ++p)
      h.push(c);
    h.push(a);
  }
  return h;
}
function hr(e) {
  for (let t = 0; t < e.length; ++t) {
    let i = e[t];
    i.from != null && i.from == i.to && i.marker.clearWhenEmpty !== !1 && e.splice(t--, 1);
  }
  return e.length ? e : null;
}
function Qs(e, t, i) {
  let l = null;
  if (e.iter(t.line, i.line + 1, (n) => {
    if (n.markedSpans)
      for (let s = 0; s < n.markedSpans.length; ++s) {
        let o = n.markedSpans[s].marker;
        o.readOnly && (!l || K(l, o) == -1) && (l || (l = [])).push(o);
      }
  }), !l)
    return null;
  let r = [{ from: t, to: i }];
  for (let n = 0; n < l.length; ++n) {
    let s = l[n], o = s.find(0);
    for (let a = 0; a < r.length; ++a) {
      let u = r[a];
      if (T(u.to, o.from) < 0 || T(u.from, o.to) > 0)
        continue;
      let f = [a, 1], h = T(u.from, o.from), d = T(u.to, o.to);
      (h < 0 || !s.inclusiveLeft && !h) && f.push({ from: u.from, to: o.from }), (d > 0 || !s.inclusiveRight && !d) && f.push({ from: o.to, to: u.to }), r.splice.apply(r, f), a += f.length - 3;
    }
  }
  return r;
}
function on(e) {
  let t = e.markedSpans;
  if (t) {
    for (let i = 0; i < t.length; ++i)
      t[i].marker.detachLine(e);
    e.markedSpans = null;
  }
}
function an(e, t) {
  if (t) {
    for (let i = 0; i < t.length; ++i)
      t[i].marker.attachLine(e);
    e.markedSpans = t;
  }
}
function yi(e) {
  return e.inclusiveLeft ? -1 : 0;
}
function mi(e) {
  return e.inclusiveRight ? 1 : 0;
}
function Ml(e, t) {
  let i = e.lines.length - t.lines.length;
  if (i != 0)
    return i;
  let l = e.find(), r = t.find(), n = T(l.from, r.from) || yi(e) - yi(t);
  if (n)
    return -n;
  let s = T(l.to, r.to) || mi(e) - mi(t);
  return s || t.id - e.id;
}
function un(e, t) {
  let i = ve && e.markedSpans, l;
  if (i)
    for (let r, n = 0; n < i.length; ++n)
      r = i[n], r.marker.collapsed && (t ? r.from : r.to) == null && (!l || Ml(l, r.marker) < 0) && (l = r.marker);
  return l;
}
function fn(e) {
  return un(e, !0);
}
function Pi(e) {
  return un(e, !1);
}
function Js(e, t) {
  let i = ve && e.markedSpans, l;
  if (i)
    for (let r = 0; r < i.length; ++r) {
      let n = i[r];
      n.marker.collapsed && (n.from == null || n.from < t) && (n.to == null || n.to > t) && (!l || Ml(l, n.marker) < 0) && (l = n.marker);
    }
  return l;
}
function dr(e, t, i, l, r) {
  let n = v(e, t), s = ve && n.markedSpans;
  if (s)
    for (let o = 0; o < s.length; ++o) {
      let a = s[o];
      if (!a.marker.collapsed)
        continue;
      let u = a.marker.find(0), f = T(u.from, i) || yi(a.marker) - yi(r), h = T(u.to, l) || mi(a.marker) - mi(r);
      if (!(f >= 0 && h <= 0 || f <= 0 && h >= 0) && (f <= 0 && (a.marker.inclusiveRight && r.inclusiveLeft ? T(u.to, i) >= 0 : T(u.to, i) > 0) || f >= 0 && (a.marker.inclusiveRight && r.inclusiveLeft ? T(u.from, l) <= 0 : T(u.from, l) < 0)))
        return !0;
    }
}
function ge(e) {
  let t;
  for (; t = fn(e); )
    e = t.find(-1, !0).line;
  return e;
}
function Vs(e) {
  let t;
  for (; t = Pi(e); )
    e = t.find(1, !0).line;
  return e;
}
function eo(e) {
  let t, i;
  for (; t = Pi(e); )
    e = t.find(1, !0).line, (i || (i = [])).push(e);
  return i;
}
function Nl(e, t) {
  let i = v(e, t), l = ge(i);
  return i == l ? t : W(l);
}
function hn(e, t) {
  if (t > e.lastLine())
    return t;
  let i = v(e, t), l;
  if (!De(e, i))
    return t;
  for (; l = Pi(i); )
    i = l.find(1, !0).line;
  return W(i) + 1;
}
function De(e, t) {
  let i = ve && t.markedSpans;
  if (i) {
    for (let l, r = 0; r < i.length; ++r)
      if (l = i[r], !!l.marker.collapsed) {
        if (l.from == null)
          return !0;
        if (!l.marker.widgetNode && l.from == 0 && l.marker.inclusiveLeft && rl(e, t, l))
          return !0;
      }
  }
}
function rl(e, t, i) {
  if (i.to == null) {
    let l = i.marker.find(1, !0);
    return rl(e, l.line, Kt(l.line.markedSpans, i.marker));
  }
  if (i.marker.inclusiveRight && i.to == t.text.length)
    return !0;
  for (let l, r = 0; r < t.markedSpans.length; ++r)
    if (l = t.markedSpans[r], l.marker.collapsed && !l.marker.widgetNode && l.from == i.to && (l.to == null || l.to != i.from) && (l.marker.inclusiveLeft || i.marker.inclusiveRight) && rl(e, t, l))
      return !0;
}
function Ce(e) {
  e = ge(e);
  let t = 0, i = e.parent;
  for (let l = 0; l < i.lines.length; ++l) {
    let r = i.lines[l];
    if (r == e)
      break;
    t += r.height;
  }
  for (let l = i.parent; l; i = l, l = i.parent)
    for (let r = 0; r < l.children.length; ++r) {
      let n = l.children[r];
      if (n == i)
        break;
      t += n.height;
    }
  return t;
}
function bi(e) {
  if (e.height == 0)
    return 0;
  let t = e.text.length, i, l = e;
  for (; i = fn(l); ) {
    let r = i.find(0, !0);
    l = r.from.line, t += r.from.ch - r.to.ch;
  }
  for (l = e; i = Pi(l); ) {
    let r = i.find(0, !0);
    t -= l.text.length - r.from.ch, l = r.to.line, t += l.text.length - r.to.ch;
  }
  return t;
}
function Al(e) {
  let t = e.display, i = e.doc;
  t.maxLine = v(i, i.first), t.maxLineLength = bi(t.maxLine), t.maxLineChanged = !0, i.iter((l) => {
    let r = bi(l);
    r > t.maxLineLength && (t.maxLineLength = r, t.maxLine = l);
  });
}
class _t {
  constructor(t, i, l) {
    this.text = t, an(this, i), this.height = l ? l(this) : 1;
  }
  lineNo() {
    return W(this);
  }
}
gt(_t);
function to(e, t, i, l) {
  e.text = t, e.stateAfter && (e.stateAfter = null), e.styles && (e.styles = null), e.order != null && (e.order = null), on(e), an(e, i);
  let r = l ? l(e) : 1;
  r != e.height && pe(e, r);
}
function io(e) {
  e.parent = null, on(e);
}
let lo = {}, ro = {};
function cr(e, t) {
  if (!e || /^\s*$/.test(e))
    return null;
  let i = t.addModeClass ? ro : lo;
  return i[e] || (i[e] = e.replace(/\S+/g, "cm-$&"));
}
function dn(e, t) {
  let i = rt("span", null, null, $ ? "padding-right: .1px" : null), l = {
    pre: rt("pre", [i], "CodeMirror-line"),
    content: i,
    col: 0,
    pos: 0,
    cm: e,
    trailingSpace: !1,
    splitSpaces: e.getOption("lineWrapping")
  };
  t.measure = {};
  for (let r = 0; r <= (t.rest ? t.rest.length : 0); r++) {
    let n = r ? t.rest[r - 1] : t.line, s;
    l.pos = 0, l.addToken = so, Ps(e.display.measure) && (s = Le(n, e.doc.direction)) && (l.addToken = ao(l.addToken, s)), l.map = [];
    let o = t != e.display.externalMeasured && W(n);
    uo(n, l, rn(e, n, o)), n.styleClasses && (n.styleClasses.bgClass && (l.bgClass = _i(n.styleClasses.bgClass, l.bgClass || "")), n.styleClasses.textClass && (l.textClass = _i(n.styleClasses.textClass, l.textClass || ""))), l.map.length == 0 && l.map.push(0, 0, l.content.appendChild(Fs(e.display.measure))), r == 0 ? (t.measure.map = l.map, t.measure.cache = {}) : ((t.measure.maps || (t.measure.maps = [])).push(l.map), (t.measure.caches || (t.measure.caches = [])).push({}));
  }
  if ($) {
    let r = l.content.lastChild;
    (/\bcm-tab\b/.test(r.className) || r.querySelector && r.querySelector(".cm-tab")) && (l.content.className = "cm-tab-wrap-hack");
  }
  return E(e, "renderLine", e, t.line, l.pre), l.pre.className && (l.textClass = _i(l.pre.className, l.textClass || "")), l;
}
function no(e) {
  let t = C("span", "•", "cm-invalidchar");
  return t.title = "\\u" + e.charCodeAt(0).toString(16), t.setAttribute("aria-label", t.title), t;
}
function so(e, t, i, l, r, n, s) {
  if (!t)
    return;
  let o = e.splitSpaces ? oo(t, e.trailingSpace) : t, a = e.cm.state.specialChars, u = !1, f;
  if (!a.test(t))
    e.col += t.length, f = document.createTextNode(o), e.map.push(e.pos, e.pos + t.length, f), N && F < 9 && (u = !0), e.pos += t.length;
  else {
    f = document.createDocumentFragment();
    let h = 0;
    for (; ; ) {
      a.lastIndex = h;
      let d = a.exec(t), c = d ? d.index - h : t.length - h;
      if (c) {
        let m = document.createTextNode(o.slice(h, h + c));
        N && F < 9 ? f.appendChild(C("span", [m])) : f.appendChild(m), e.map.push(e.pos, e.pos + c, m), e.col += c, e.pos += c;
      }
      if (!d)
        break;
      h += c + 1;
      let p;
      if (d[0] == "	") {
        let m = e.cm.options.tabSize, g = m - e.col % m;
        p = f.appendChild(C("span", ml(g), "cm-tab")), p.setAttribute("role", "presentation"), p.setAttribute("cm-text", "	"), e.col += g;
      } else
        d[0] == "\r" || d[0] == `
` ? (p = f.appendChild(C("span", d[0] == "\r" ? "␍" : "␤", "cm-invalidchar")), p.setAttribute("cm-text", d[0]), e.col += 1) : (p = e.cm.options.specialCharPlaceholder(d[0]), p.setAttribute("cm-text", d[0]), N && F < 9 ? f.appendChild(C("span", [p])) : f.appendChild(p), e.col += 1);
      e.map.push(e.pos, e.pos + 1, p), e.pos++;
    }
  }
  if (e.trailingSpace = o.charCodeAt(t.length - 1) == 32, i || l || r || u || n || s) {
    let h = i || "";
    l && (h += l), r && (h += r);
    let d = C("span", [f], h, n);
    if (s)
      for (let c in s)
        s.hasOwnProperty(c) && c != "style" && c != "class" && d.setAttribute(c, s[c]);
    return e.content.appendChild(d);
  }
  e.content.appendChild(f);
}
function oo(e, t) {
  if (e.length > 1 && !/  /.test(e))
    return e;
  let i = t, l = "";
  for (let r = 0; r < e.length; r++) {
    let n = e.charAt(r);
    n == " " && i && (r == e.length - 1 || e.charCodeAt(r + 1) == 32) && (n = " "), l += n, i = n == " ";
  }
  return l;
}
function ao(e, t) {
  return (i, l, r, n, s, o, a) => {
    r = r ? r + " cm-force-border" : "cm-force-border";
    let u = i.pos, f = u + l.length;
    for (; ; ) {
      let h;
      for (let d = 0; d < t.length && (h = t[d], !(h.to > u && h.from <= u)); d++)
        ;
      if (h.to >= f)
        return e(i, l, r, n, s, o, a);
      e(i, l.slice(0, h.to - u), r, n, null, o, a), n = null, l = l.slice(h.to - u), u = h.to;
    }
  };
}
function pr(e, t, i, l) {
  let r = !l && i.widgetNode;
  r && e.map.push(e.pos, e.pos + t, r), !l && e.cm.display.input.needsContentAttribute && (r || (r = e.content.appendChild(document.createElement("span"))), r.setAttribute("cm-marker", i.id)), r && (e.cm.display.input.setUneditable(r), e.content.appendChild(r)), e.pos += t, e.trailingSpace = !1;
}
function uo(e, t, i) {
  let l = e.markedSpans, r = e.text, n = 0;
  if (!l) {
    for (let y = 1; y < i.length; y += 2)
      t.addToken(t, r.slice(n, n = i[y]), cr(i[y + 1], t.cm.options));
    return;
  }
  let s = r.length, o = 0, a = 1, u = "", f, h, d = 0, c, p, m, g, b;
  for (; ; ) {
    if (d == o) {
      c = p = m = h = "", b = null, g = null, d = 1 / 0;
      let L = [], w;
      for (let M = 0; M < l.length; ++M) {
        let A = l[M], D = A.marker;
        if (D.type == "bookmark" && A.from == o && D.widgetNode)
          L.push(D);
        else if (A.from <= o && (A.to == null || A.to > o || D.collapsed && A.to == o && A.from == o)) {
          if (A.to != null && A.to != o && d > A.to && (d = A.to, p = ""), D.className && (c += " " + D.className), D.css && (h = (h ? h + ";" : "") + D.css), D.startStyle && A.from == o && (m += " " + D.startStyle), D.endStyle && A.to == d && (w || (w = [])).push(D.endStyle, A.to), D.title && ((b || (b = {})).title = D.title), D.attributes)
            for (let Q in D.attributes)
              (b || (b = {}))[Q] = D.attributes[Q];
          D.collapsed && (!g || Ml(g.marker, D) < 0) && (g = A);
        } else
          A.from > o && d > A.from && (d = A.from);
      }
      if (w)
        for (let M = 0; M < w.length; M += 2)
          w[M + 1] == d && (p += " " + w[M]);
      if (!g || g.from == o)
        for (let M = 0; M < L.length; ++M)
          pr(t, 0, L[M]);
      if (g && (g.from || 0) == o) {
        if (pr(
          t,
          (g.to == null ? s + 1 : g.to) - o,
          g.marker,
          g.from == null
        ), g.to == null)
          return;
        g.to == o && (g = !1);
      }
    }
    if (o >= s)
      break;
    let y = Math.min(s, d);
    for (; ; ) {
      if (u) {
        let L = o + u.length;
        if (!g) {
          let w = L > y ? u.slice(0, y - o) : u;
          t.addToken(
            t,
            w,
            f ? f + c : c,
            m,
            o + w.length == d ? p : "",
            h,
            b
          );
        }
        if (L >= y) {
          u = u.slice(y - o), o = y;
          break;
        }
        o = L, m = "";
      }
      u = r.slice(n, n = i[a++]), f = cr(i[a++], t.cm.options);
    }
  }
}
function cn(e, t, i) {
  this.line = t, this.rest = eo(t), this.size = this.rest ? W(O(this.rest)) - i + 1 : 1, this.node = this.text = null, this.hidden = De(e, t);
}
function fi(e, t, i) {
  let l = [], r;
  for (let n = t; n < i; n = r) {
    let s = new cn(e.doc, v(e.doc, n), n);
    r = n + s.size, l.push(s);
  }
  return l;
}
let ot = null;
function fo(e) {
  ot ? ot.ops.push(e) : e.ownsGroup = ot = {
    ops: [e],
    delayedCallbacks: []
  };
}
function ho(e) {
  let t = e.delayedCallbacks, i = 0;
  do {
    for (; i < t.length; i++)
      t[i].call(null);
    for (let l = 0; l < e.ops.length; l++) {
      let r = e.ops[l];
      if (r.cursorActivityHandlers)
        for (; r.cursorActivityCalled < r.cursorActivityHandlers.length; )
          r.cursorActivityHandlers[r.cursorActivityCalled++].call(null, r.cm);
    }
  } while (i < t.length);
}
function co(e, t) {
  let i = e.ownsGroup;
  if (i)
    try {
      ho(i);
    } finally {
      ot = null, t(i);
    }
}
let Dt = null;
function z(e, t) {
  let i = bl(e, t);
  if (!i.length)
    return;
  let l = Array.prototype.slice.call(arguments, 2), r;
  ot ? r = ot.delayedCallbacks : Dt ? r = Dt : (r = Dt = [], setTimeout(po, 0));
  for (let n = 0; n < i.length; ++n)
    r.push(() => i[n].apply(null, l));
}
function po() {
  let e = Dt;
  Dt = null;
  for (let t = 0; t < e.length; ++t)
    e[t]();
}
function pn(e, t, i, l) {
  for (let r = 0; r < t.changes.length; r++) {
    let n = t.changes[r];
    n == "text" ? yo(e, t) : n == "gutter" ? yn(e, t, i, l) : n == "class" ? Dl(e, t) : n == "widget" && mo(e, t, l);
  }
  t.changes = null;
}
function Xt(e) {
  return e.node == e.text && (e.node = C("div", null, null, "position: relative"), e.text.parentNode && e.text.parentNode.replaceChild(e.node, e.text), e.node.appendChild(e.text), N && F < 8 && (e.node.style.zIndex = 2)), e.node;
}
function go(e, t) {
  let i = t.bgClass ? t.bgClass + " " + (t.line.bgClass || "") : t.line.bgClass;
  if (i && (i += " CodeMirror-linebackground"), t.background)
    i ? t.background.className = i : (t.background.parentNode.removeChild(t.background), t.background = null);
  else if (i) {
    let l = Xt(t);
    t.background = l.insertBefore(C("div", null, i), l.firstChild), e.display.input.setUneditable(t.background);
  }
}
function gn(e, t) {
  let i = e.display.externalMeasured;
  return i && i.line == t.line ? (e.display.externalMeasured = null, t.measure = i.measure, i.built) : dn(e, t);
}
function yo(e, t) {
  let i = t.text.className, l = gn(e, t);
  t.text == t.node && (t.node = l.pre), t.text.parentNode.replaceChild(l.pre, t.text), t.text = l.pre, l.bgClass != t.bgClass || l.textClass != t.textClass ? (t.bgClass = l.bgClass, t.textClass = l.textClass, Dl(e, t)) : i && (t.text.className = i);
}
function Dl(e, t) {
  go(e, t), t.line.wrapClass ? Xt(t).className = t.line.wrapClass : t.node != t.text && (t.node.className = "");
  let i = t.textClass ? t.textClass + " " + (t.line.textClass || "") : t.line.textClass;
  t.text.className = i || "";
}
function yn(e, t, i, l) {
  if (t.gutter && (t.node.removeChild(t.gutter), t.gutter = null), t.gutterBackground && (t.node.removeChild(t.gutterBackground), t.gutterBackground = null), t.line.gutterClass) {
    let n = Xt(t);
    t.gutterBackground = C(
      "div",
      null,
      "CodeMirror-gutter-background " + t.line.gutterClass,
      `left: ${e.options.fixedGutter ? l.fixedPos : -l.gutterTotalWidth}px; width: ${l.gutterTotalWidth}px`
    ), e.display.input.setUneditable(t.gutterBackground), n.insertBefore(t.gutterBackground, t.text);
  }
  let r = t.line.gutterMarkers;
  if (e.options.lineNumbers || r) {
    let n = Xt(t), s = t.gutter = C("div", null, "CodeMirror-gutter-wrapper", `left: ${e.options.fixedGutter ? l.fixedPos : -l.gutterTotalWidth}px`);
    if (s.setAttribute("aria-hidden", "true"), e.display.input.setUneditable(s), n.insertBefore(s, t.text), t.line.gutterClass && (s.className += " " + t.line.gutterClass), e.options.lineNumbers && (!r || !r["CodeMirror-linenumbers"]) && (t.lineNumber = s.appendChild(
      C(
        "div",
        Ll(e.options, i),
        "CodeMirror-linenumber CodeMirror-gutter-elt",
        `left: ${l.gutterLeft["CodeMirror-linenumbers"]}px; width: ${e.display.lineNumInnerWidth}px`
      )
    )), r)
      for (let o = 0; o < e.display.gutterSpecs.length; ++o) {
        let a = e.display.gutterSpecs[o].className, u = r.hasOwnProperty(a) && r[a];
        u && s.appendChild(C(
          "div",
          [u],
          "CodeMirror-gutter-elt",
          `left: ${l.gutterLeft[a]}px; width: ${l.gutterWidth[a]}px`
        ));
      }
  }
}
function mo(e, t, i) {
  t.alignable && (t.alignable = null);
  let l = ut("CodeMirror-linewidget");
  for (let r = t.node.firstChild, n; r; r = n)
    n = r.nextSibling, l.test(r.className) && t.node.removeChild(r);
  mn(e, t, i);
}
function bo(e, t, i, l) {
  let r = gn(e, t);
  return t.text = t.node = r.pre, r.bgClass && (t.bgClass = r.bgClass), r.textClass && (t.textClass = r.textClass), Dl(e, t), yn(e, t, i, l), mn(e, t, l), t.node;
}
function mn(e, t, i) {
  if (gr(e, t.line, t, i, !0), t.rest)
    for (let l = 0; l < t.rest.length; l++)
      gr(e, t.rest[l], t, i, !1);
}
function gr(e, t, i, l, r) {
  if (!t.widgets)
    return;
  let n = Xt(i);
  for (let s = 0, o = t.widgets; s < o.length; ++s) {
    let a = o[s], u = C("div", [a.node], "CodeMirror-linewidget" + (a.className ? " " + a.className : ""));
    a.handleMouseEvents || u.setAttribute("cm-ignore-events", "true"), xo(a, u, i, l), e.display.input.setUneditable(u), r && a.above ? n.insertBefore(u, i.gutter || i.text) : n.appendChild(u), z(a, "redraw");
  }
}
function xo(e, t, i, l) {
  if (e.noHScroll) {
    (i.alignable || (i.alignable = [])).push(t);
    let r = l.wrapperWidth;
    t.style.left = l.fixedPos + "px", e.coverGutter || (r -= l.gutterTotalWidth, t.style.paddingLeft = l.gutterTotalWidth + "px"), t.style.width = r + "px";
  }
  e.coverGutter && (t.style.zIndex = 5, t.style.position = "relative", e.noHScroll || (t.style.marginLeft = -l.gutterTotalWidth + "px"));
}
function $t(e) {
  if (e.height != null)
    return e.height;
  let t = e.doc.cm;
  if (!t)
    return 0;
  if (!Ae(document.body, e.node)) {
    let i = "position: relative;";
    e.coverGutter && (i += "margin-left: -" + t.display.gutters.offsetWidth + "px;"), e.noHScroll && (i += "width: " + t.display.wrapper.clientWidth + "px;"), ie(t.display.measure, C("div", [e.node], null, i));
  }
  return e.height = e.node.parentNode.offsetHeight;
}
function Se(e, t) {
  for (let i = xl(t); i != e.wrapper; i = i.parentNode)
    if (!i || i.nodeType == 1 && i.getAttribute("cm-ignore-events") == "true" || i.parentNode == e.sizer && i != e.mover)
      return !0;
}
function Ei(e) {
  return e.lineSpace.offsetTop;
}
function Ol(e) {
  return e.mover.offsetHeight - e.lineSpace.offsetHeight;
}
function bn(e) {
  if (e.cachedPaddingH)
    return e.cachedPaddingH;
  let t = ie(e.measure, C("pre", "x", "CodeMirror-line-like")), i = window.getComputedStyle ? window.getComputedStyle(t) : t.currentStyle, l = { left: parseInt(i.paddingLeft), right: parseInt(i.paddingRight) };
  return !isNaN(l.left) && !isNaN(l.right) && (e.cachedPaddingH = l), l;
}
function ye(e) {
  return Yr - e.display.nativeBarWidth;
}
function Ye(e) {
  return e.display.scroller.clientWidth - ye(e) - e.display.barWidth;
}
function Wl(e) {
  return e.display.scroller.clientHeight - ye(e) - e.display.barHeight;
}
function wo(e, t, i) {
  let l = e.options.lineWrapping, r = l && Ye(e);
  if (!t.measure.heights || l && t.measure.width != r) {
    let n = t.measure.heights = [];
    if (l) {
      t.measure.width = r;
      let s = t.text.firstChild.getClientRects();
      for (let o = 0; o < s.length - 1; o++) {
        let a = s[o], u = s[o + 1];
        Math.abs(a.bottom - u.bottom) > 2 && n.push((a.bottom + u.top) / 2 - i.top);
      }
    }
    n.push(i.bottom - i.top);
  }
}
function xn(e, t, i) {
  if (e.line == t)
    return { map: e.measure.map, cache: e.measure.cache };
  for (let l = 0; l < e.rest.length; l++)
    if (e.rest[l] == t)
      return { map: e.measure.maps[l], cache: e.measure.caches[l] };
  for (let l = 0; l < e.rest.length; l++)
    if (W(e.rest[l]) > i)
      return { map: e.measure.maps[l], cache: e.measure.caches[l], before: !0 };
}
function vo(e, t) {
  t = ge(t);
  let i = W(t), l = e.display.externalMeasured = new cn(e.doc, t, i);
  l.lineN = i;
  let r = l.built = dn(e, l);
  return l.text = r.pre, ie(e.display.lineMeasure, r.pre), l;
}
function wn(e, t, i, l) {
  return me(e, yt(e, t), i, l);
}
function Hl(e, t) {
  if (t >= e.display.viewFrom && t < e.display.viewTo)
    return e.display.view[_e(e, t)];
  let i = e.display.externalMeasured;
  if (i && t >= i.lineN && t < i.lineN + i.size)
    return i;
}
function yt(e, t) {
  let i = W(t), l = Hl(e, i);
  l && !l.text ? l = null : l && l.changes && (pn(e, l, i, El(e)), e.curOp.forceUpdate = !0), l || (l = vo(e, t));
  let r = xn(l, t, i);
  return {
    line: t,
    view: l,
    rect: null,
    map: r.map,
    cache: r.cache,
    before: r.before,
    hasHeights: !1
  };
}
function me(e, t, i, l, r) {
  t.before && (i = -1);
  let n = i + (l || ""), s;
  return t.cache.hasOwnProperty(n) ? s = t.cache[n] : (t.rect || (t.rect = t.view.text.getBoundingClientRect()), t.hasHeights || (wo(e, t.view, t.rect), t.hasHeights = !0), s = So(e, t, i, l), s.bogus || (t.cache[n] = s)), {
    left: s.left,
    right: s.right,
    top: r ? s.rtop : s.top,
    bottom: r ? s.rbottom : s.bottom
  };
}
let vn = { left: 0, right: 0, top: 0, bottom: 0 };
function Cn(e, t, i) {
  let l, r, n, s, o, a;
  for (let u = 0; u < e.length; u += 3)
    if (o = e[u], a = e[u + 1], t < o ? (r = 0, n = 1, s = "left") : t < a ? (r = t - o, n = r + 1) : (u == e.length - 3 || t == a && e[u + 3] > t) && (n = a - o, r = n - 1, t >= a && (s = "right")), r != null) {
      if (l = e[u + 2], o == a && i == (l.insertLeft ? "left" : "right") && (s = i), i == "left" && r == 0)
        for (; u && e[u - 2] == e[u - 3] && e[u - 1].insertLeft; )
          l = e[(u -= 3) + 2], s = "left";
      if (i == "right" && r == a - o)
        for (; u < e.length - 3 && e[u + 3] == e[u + 4] && !e[u + 5].insertLeft; )
          l = e[(u += 3) + 2], s = "right";
      break;
    }
  return { node: l, start: r, end: n, collapse: s, coverStart: o, coverEnd: a };
}
function Co(e, t) {
  let i = vn;
  if (t == "left")
    for (let l = 0; l < e.length && (i = e[l]).left == i.right; l++)
      ;
  else
    for (let l = e.length - 1; l >= 0 && (i = e[l]).left == i.right; l--)
      ;
  return i;
}
function So(e, t, i, l) {
  let r = Cn(t.map, i, l), n = r.node, s = r.start, o = r.end, a = r.collapse, u;
  if (n.nodeType == 3) {
    for (let y = 0; y < 4; y++) {
      for (; s && Vi(t.line.text.charAt(r.coverStart + s)); )
        --s;
      for (; r.coverStart + o < r.coverEnd && Vi(t.line.text.charAt(r.coverStart + o)); )
        ++o;
      if (N && F < 9 && s == 0 && o == r.coverEnd - r.coverStart ? u = n.parentNode.getBoundingClientRect() : u = Co(Ge(n, s, o).getClientRects(), l), u.left || u.right || s == 0)
        break;
      o = s, s = s - 1, a = "right";
    }
    N && F < 11 && (u = Lo(e.display.measure, u));
  } else {
    s > 0 && (a = l = "right");
    let y;
    e.options.lineWrapping && (y = n.getClientRects()).length > 1 ? u = y[l == "right" ? y.length - 1 : 0] : u = n.getBoundingClientRect();
  }
  if (N && F < 9 && !s && (!u || !u.left && !u.right)) {
    let y = n.parentNode.getClientRects()[0];
    y ? u = { left: y.left, right: y.left + mt(e.display), top: y.top, bottom: y.bottom } : u = vn;
  }
  let f = u.top - t.rect.top, h = u.bottom - t.rect.top, d = (f + h) / 2, c = t.view.measure.heights, p = 0;
  for (; p < c.length - 1 && !(d < c[p]); p++)
    ;
  let m = p ? c[p - 1] : 0, g = c[p], b = {
    left: (a == "right" ? u.right : u.left) - t.rect.left,
    right: (a == "left" ? u.left : u.right) - t.rect.left,
    top: m,
    bottom: g
  };
  return !u.left && !u.right && (b.bogus = !0), e.options.singleCursorHeightPerLine || (b.rtop = f, b.rbottom = h), b;
}
function Lo(e, t) {
  if (!window.screen || screen.logicalXDPI == null || screen.logicalXDPI == screen.deviceXDPI || !Rs(e))
    return t;
  let i = screen.logicalXDPI / screen.deviceXDPI, l = screen.logicalYDPI / screen.deviceYDPI;
  return {
    left: t.left * i,
    right: t.right * i,
    top: t.top * l,
    bottom: t.bottom * l
  };
}
function Sn(e) {
  if (e.measure && (e.measure.cache = {}, e.measure.heights = null, e.rest))
    for (let t = 0; t < e.rest.length; t++)
      e.measure.caches[t] = {};
}
function Ln(e) {
  e.display.externalMeasure = null, Ne(e.display.lineMeasure);
  for (let t = 0; t < e.display.view.length; t++)
    Sn(e.display.view[t]);
}
function Yt(e) {
  Ln(e), e.display.cachedCharWidth = e.display.cachedTextHeight = e.display.cachedPaddingH = null, e.options.lineWrapping || (e.display.maxLineChanged = !0), e.display.lineNumChars = null;
}
function kn() {
  return Ti && Ni ? -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) : window.pageXOffset || (document.documentElement || document.body).scrollLeft;
}
function Tn() {
  return Ti && Ni ? -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) : window.pageYOffset || (document.documentElement || document.body).scrollTop;
}
function Fl(e) {
  let t = 0;
  if (e.widgets)
    for (let i = 0; i < e.widgets.length; ++i)
      e.widgets[i].above && (t += $t(e.widgets[i]));
  return t;
}
function Ii(e, t, i, l, r) {
  if (!r) {
    let s = Fl(t);
    i.top += s, i.bottom += s;
  }
  if (l == "line")
    return i;
  l || (l = "local");
  let n = Ce(t);
  if (l == "local" ? n += Ei(e.display) : n -= e.display.viewOffset, l == "page" || l == "window") {
    let s = e.display.lineSpace.getBoundingClientRect();
    n += s.top + (l == "window" ? 0 : Tn());
    let o = s.left + (l == "window" ? 0 : kn());
    i.left += o, i.right += o;
  }
  return i.top += n, i.bottom += n, i;
}
function yr(e, t, i) {
  if (i == "div")
    return t;
  let l = t.left, r = t.top;
  if (i == "page")
    l -= kn(), r -= Tn();
  else if (i == "local" || !i) {
    let s = e.display.sizer.getBoundingClientRect();
    l += s.left, r += s.top;
  }
  let n = e.display.lineSpace.getBoundingClientRect();
  return { left: l - n.left, top: r - n.top };
}
function xi(e, t, i, l, r) {
  return l || (l = v(e.doc, t.line)), Ii(e, l, wn(e, l, t.ch, r), i);
}
function ae(e, t, i, l, r, n) {
  l = l || v(e.doc, t.line), r || (r = yt(e, l));
  function s(p, m) {
    let g = me(e, r, p, m ? "right" : "left", n);
    return m ? g.left = g.right : g.right = g.left, Ii(e, l, g, i);
  }
  let o = Le(l, e.doc.direction), a = t.ch, u = t.sticky;
  if (a >= l.text.length ? (a = l.text.length, u = "before") : a <= 0 && (a = 0, u = "after"), !o)
    return s(u == "before" ? a - 1 : a, u == "before");
  function f(p, m, g) {
    let b = o[m], y = b.level == 1;
    return s(g ? p - 1 : p, y != g);
  }
  let h = zt(o, a, u), d = Tt, c = f(a, h, u == "before");
  return d != null && (c.other = f(a, d, u != "before")), c;
}
function mr(e, t) {
  let i = 0;
  t = k(e.doc, t), e.options.lineWrapping || (i = mt(e.display) * t.ch);
  let l = v(e.doc, t.line), r = Ce(l) + Ei(e.display);
  return { left: i, right: i, top: r, bottom: r + l.height };
}
function nl(e, t, i, l, r) {
  let n = x(e, t, i);
  return n.xRel = r, l && (n.outside = l), n;
}
function Pl(e, t, i) {
  let l = e.doc;
  if (i += e.display.viewOffset, i < 0)
    return nl(l.first, 0, null, -1, -1);
  let r = Ie(l, i), n = l.first + l.size - 1;
  if (r > n)
    return nl(l.first + l.size - 1, v(l, n).text.length, null, 1, 1);
  t < 0 && (t = 0);
  let s = v(l, r);
  for (; ; ) {
    let o = ko(e, s, r, t, i), a = Js(s, o.ch + (o.xRel > 0 || o.outside > 0 ? 1 : 0));
    if (!a)
      return o;
    let u = a.find(1);
    if (u.line == r)
      return u;
    s = v(l, r = u.line);
  }
}
function Mn(e, t, i, l) {
  l -= Fl(t);
  let r = t.text.length, n = Bt((s) => me(e, i, s - 1).bottom <= l, r, 0);
  return r = Bt((s) => me(e, i, s).top > l, n, r), { begin: n, end: r };
}
function Nn(e, t, i, l) {
  i || (i = yt(e, t));
  let r = Ii(e, t, me(e, i, l), "line").top;
  return Mn(e, t, i, r);
}
function sl(e, t, i, l) {
  return e.bottom <= i ? !1 : e.top > i ? !0 : (l ? e.left : e.right) > t;
}
function ko(e, t, i, l, r) {
  r -= Ce(t);
  let n = yt(e, t), s = Fl(t), o = 0, a = t.text.length, u = !0, f = Le(t, e.doc.direction);
  if (f) {
    let b = (e.options.lineWrapping ? Mo : To)(e, t, i, n, f, l, r);
    u = b.level != 1, o = u ? b.from : b.to - 1, a = u ? b.to : b.from - 1;
  }
  let h = null, d = null, c = Bt((b) => {
    let y = me(e, n, b);
    return y.top += s, y.bottom += s, sl(y, l, r, !1) ? (y.top <= r && y.left <= l && (h = b, d = y), !0) : !1;
  }, o, a), p, m, g = !1;
  if (d) {
    let b = l - d.left < d.right - l, y = b == u;
    c = h + (y ? 0 : 1), m = y ? "after" : "before", p = b ? d.left : d.right;
  } else {
    !u && (c == a || c == o) && c++, m = c == 0 ? "after" : c == t.text.length ? "before" : me(e, n, c - (u ? 1 : 0)).bottom + s <= r == u ? "after" : "before";
    let b = ae(e, x(i, c, m), "line", t, n);
    p = b.left, g = r < b.top ? -1 : r >= b.bottom ? 1 : 0;
  }
  return c = qr(t.text, c, 1), nl(i, c, m, g, l - p);
}
function To(e, t, i, l, r, n, s) {
  let o = Bt((u) => {
    let f = r[u], h = f.level != 1;
    return sl(ae(
      e,
      x(i, h ? f.to : f.from, h ? "before" : "after"),
      "line",
      t,
      l
    ), n, s, !0);
  }, 0, r.length - 1), a = r[o];
  if (o > 0) {
    let u = a.level != 1, f = ae(
      e,
      x(i, u ? a.from : a.to, u ? "after" : "before"),
      "line",
      t,
      l
    );
    sl(f, n, s, !0) && f.top > s && (a = r[o - 1]);
  }
  return a;
}
function Mo(e, t, i, l, r, n, s) {
  let { begin: o, end: a } = Mn(e, t, l, s);
  /\s/.test(t.text.charAt(a - 1)) && a--;
  let u = null, f = null;
  for (let h = 0; h < r.length; h++) {
    let d = r[h];
    if (d.from >= a || d.to <= o)
      continue;
    let c = d.level != 1, p = me(e, l, c ? Math.min(a, d.to) - 1 : Math.max(o, d.from)).right, m = p < n ? n - p + 1e9 : p - n;
    (!u || f > m) && (u = d, f = m);
  }
  return u || (u = r[r.length - 1]), u.from < o && (u = { from: o, to: u.to, level: u.level }), u.to > a && (u = { from: u.from, to: a, level: u.level }), u;
}
let Ee;
function ht(e) {
  if (e.cachedTextHeight != null)
    return e.cachedTextHeight;
  if (Ee == null) {
    Ee = C("pre", null, "CodeMirror-line-like");
    for (let i = 0; i < 49; ++i)
      Ee.appendChild(document.createTextNode("x")), Ee.appendChild(C("br"));
    Ee.appendChild(document.createTextNode("x"));
  }
  ie(e.measure, Ee);
  let t = Ee.offsetHeight / 50;
  return t > 3 && (e.cachedTextHeight = t), Ne(e.measure), t || 1;
}
function mt(e) {
  if (e.cachedCharWidth != null)
    return e.cachedCharWidth;
  let t = C("span", "xxxxxxxxxx"), i = C("pre", [t], "CodeMirror-line-like");
  ie(e.measure, i);
  let l = t.getBoundingClientRect(), r = (l.right - l.left) / 10;
  return r > 2 && (e.cachedCharWidth = r), r || 10;
}
function El(e) {
  let t = e.display, i = {}, l = {}, r = t.gutters.clientLeft;
  for (let n = t.gutters.firstChild, s = 0; n; n = n.nextSibling, ++s) {
    let o = e.display.gutterSpecs[s].className;
    i[o] = n.offsetLeft + n.clientLeft + r, l[o] = n.clientWidth;
  }
  return {
    fixedPos: Il(t),
    gutterTotalWidth: t.gutters.offsetWidth,
    gutterLeft: i,
    gutterWidth: l,
    wrapperWidth: t.wrapper.clientWidth
  };
}
function Il(e) {
  return e.scroller.getBoundingClientRect().left - e.sizer.getBoundingClientRect().left;
}
function An(e) {
  let t = ht(e.display), i = e.options.lineWrapping, l = i && Math.max(5, e.display.scroller.clientWidth / mt(e.display) - 3);
  return (r) => {
    if (De(e.doc, r))
      return 0;
    let n = 0;
    if (r.widgets)
      for (let s = 0; s < r.widgets.length; s++)
        r.widgets[s].height && (n += r.widgets[s].height);
    return i ? n + (Math.ceil(r.text.length / l) || 1) * t : n + t;
  };
}
function Rl(e) {
  let t = e.doc, i = An(e);
  t.iter((l) => {
    let r = i(l);
    r != l.height && pe(l, r);
  });
}
function Ke(e, t, i, l) {
  let r = e.display;
  if (!i && xl(t).getAttribute("cm-not-content") == "true")
    return null;
  let n, s, o = r.lineSpace.getBoundingClientRect();
  try {
    n = t.clientX - o.left, s = t.clientY - o.top;
  } catch {
    return null;
  }
  let a = Pl(e, n, s), u;
  if (l && a.xRel > 0 && (u = v(e.doc, a.line).text).length == a.ch) {
    let f = le(u, u.length, e.options.tabSize) - u.length;
    a = x(a.line, Math.max(0, Math.round((n - bn(e.display).left) / mt(e.display)) - f));
  }
  return a;
}
function _e(e, t) {
  if (t >= e.display.viewTo || (t -= e.display.viewFrom, t < 0))
    return null;
  let i = e.display.view;
  for (let l = 0; l < i.length; l++)
    if (t -= i[l].size, t < 0)
      return l;
}
function q(e, t, i, l) {
  t == null && (t = e.doc.first), i == null && (i = e.doc.first + e.doc.size), l || (l = 0);
  let r = e.display;
  if (l && i < r.viewTo && (r.updateLineNumbers == null || r.updateLineNumbers > t) && (r.updateLineNumbers = t), e.curOp.viewChanged = !0, t >= r.viewTo)
    ve && Nl(e.doc, t) < r.viewTo && Te(e);
  else if (i <= r.viewFrom)
    ve && hn(e.doc, i + l) > r.viewFrom ? Te(e) : (r.viewFrom += l, r.viewTo += l);
  else if (t <= r.viewFrom && i >= r.viewTo)
    Te(e);
  else if (t <= r.viewFrom) {
    let s = ri(e, i, i + l, 1);
    s ? (r.view = r.view.slice(s.index), r.viewFrom = s.lineN, r.viewTo += l) : Te(e);
  } else if (i >= r.viewTo) {
    let s = ri(e, t, t, -1);
    s ? (r.view = r.view.slice(0, s.index), r.viewTo = s.lineN) : Te(e);
  } else {
    let s = ri(e, t, t, -1), o = ri(e, i, i + l, 1);
    s && o ? (r.view = r.view.slice(0, s.index).concat(fi(e, s.lineN, o.lineN)).concat(r.view.slice(o.index)), r.viewTo += l) : Te(e);
  }
  let n = r.externalMeasured;
  n && (i < n.lineN ? n.lineN += l : t < n.lineN + n.size && (r.externalMeasured = null));
}
function Fe(e, t, i) {
  e.curOp.viewChanged = !0;
  let l = e.display, r = e.display.externalMeasured;
  if (r && t >= r.lineN && t < r.lineN + r.size && (l.externalMeasured = null), t < l.viewFrom || t >= l.viewTo)
    return;
  let n = l.view[_e(e, t)];
  if (n.node == null)
    return;
  let s = n.changes || (n.changes = []);
  K(s, i) == -1 && s.push(i);
}
function Te(e) {
  e.display.viewFrom = e.display.viewTo = e.doc.first, e.display.view = [], e.display.viewOffset = 0;
}
function ri(e, t, i, l) {
  let r = _e(e, t), n, s = e.display.view;
  if (!ve || i == e.doc.first + e.doc.size)
    return { index: r, lineN: i };
  let o = e.display.viewFrom;
  for (let a = 0; a < r; a++)
    o += s[a].size;
  if (o != t) {
    if (l > 0) {
      if (r == s.length - 1)
        return null;
      n = o + s[r].size - t, r++;
    } else
      n = o - t;
    t += n, i += n;
  }
  for (; Nl(e.doc, i) != i; ) {
    if (r == (l < 0 ? 0 : s.length - 1))
      return null;
    i += l * s[r - (l < 0 ? 1 : 0)].size, r += l;
  }
  return { index: r, lineN: i };
}
function No(e, t, i) {
  let l = e.display;
  l.view.length == 0 || t >= l.viewTo || i <= l.viewFrom ? (l.view = fi(e, t, i), l.viewFrom = t) : (l.viewFrom > t ? l.view = fi(e, t, l.viewFrom).concat(l.view) : l.viewFrom < t && (l.view = l.view.slice(_e(e, t))), l.viewFrom = t, l.viewTo < i ? l.view = l.view.concat(fi(e, l.viewTo, i)) : l.viewTo > i && (l.view = l.view.slice(0, _e(e, i)))), l.viewTo = i;
}
function br(e) {
  let t = e.display.view, i = 0;
  for (let l = 0; l < t.length; l++) {
    let r = t[l];
    !r.hidden && (!r.node || r.changes) && ++i;
  }
  return i;
}
function Ot(e) {
  e.display.input.showSelection(e.display.input.prepareSelection());
}
function Dn(e, t = !0) {
  let i = e.doc, l = {}, r = l.cursors = document.createDocumentFragment(), n = l.selection = document.createDocumentFragment();
  for (let s = 0; s < i.sel.ranges.length; s++) {
    if (!t && s == i.sel.primIndex)
      continue;
    let o = i.sel.ranges[s];
    if (o.from().line >= e.display.viewTo || o.to().line < e.display.viewFrom)
      continue;
    let a = o.empty();
    (a || e.options.showCursorWhenSelecting) && On(e, o.head, r), a || Ao(e, o, n);
  }
  return l;
}
function On(e, t, i) {
  let l = ae(e, t, "div", null, null, !e.options.singleCursorHeightPerLine), r = i.appendChild(C("div", " ", "CodeMirror-cursor"));
  if (r.style.left = l.left + "px", r.style.top = l.top + "px", r.style.height = Math.max(0, l.bottom - l.top) * e.options.cursorHeight + "px", /\bcm-fat-cursor\b/.test(e.getWrapperElement().className)) {
    let n = xi(e, t, "div", null, null);
    n.right - n.left > 0 && (r.style.width = n.right - n.left + "px");
  }
  if (l.other) {
    let n = i.appendChild(C("div", " ", "CodeMirror-cursor CodeMirror-secondarycursor"));
    n.style.display = "", n.style.left = l.other.left + "px", n.style.top = l.other.top + "px", n.style.height = (l.other.bottom - l.other.top) * 0.85 + "px";
  }
}
function ni(e, t) {
  return e.top - t.top || e.left - t.left;
}
function Ao(e, t, i) {
  let l = e.display, r = e.doc, n = document.createDocumentFragment(), s = bn(e.display), o = s.left, a = Math.max(l.sizerWidth, Ye(e) - l.sizer.offsetLeft) - s.right, u = r.direction == "ltr";
  function f(p, m, g, b) {
    m < 0 && (m = 0), m = Math.round(m), b = Math.round(b), n.appendChild(C("div", null, "CodeMirror-selected", `position: absolute; left: ${p}px;
                             top: ${m}px; width: ${g == null ? a - p : g}px;
                             height: ${b - m}px`));
  }
  function h(p, m, g) {
    let b = v(r, p), y = b.text.length, L, w;
    function M(Q, _) {
      return xi(e, x(p, Q), "div", b, _);
    }
    function A(Q, _, he) {
      let de = Nn(e, b, null, Q), V = _ == "ltr" == (he == "after") ? "left" : "right", G = he == "after" ? de.begin : de.end - (/\s/.test(b.text.charAt(de.end - 1)) ? 2 : 1);
      return M(G, V)[V];
    }
    let D = Le(b, r.direction);
    return Os(D, m || 0, g == null ? y : g, (Q, _, he, de) => {
      let V = he == "ltr", G = M(Q, V ? "left" : "right"), ee = M(_ - 1, V ? "right" : "left"), ti = m == null && Q == 0, ii = g == null && _ == y, Ui = de == 0, Ki = !D || de == D.length - 1;
      if (ee.top - G.top <= 3) {
        let Qe = (u ? ti : ii) && Ui, vt = (u ? ii : ti) && Ki, Pe = Qe ? o : (V ? G : ee).left, Ct = vt ? a : (V ? ee : G).right;
        f(Pe, G.top, Ct - Pe, G.bottom);
      } else {
        let Qe, vt, Pe, Ct;
        V ? (Qe = u && ti && Ui ? o : G.left, vt = u ? a : A(Q, he, "before"), Pe = u ? o : A(_, he, "after"), Ct = u && ii && Ki ? a : ee.right) : (Qe = u ? A(Q, he, "before") : o, vt = !u && ti && Ui ? a : G.right, Pe = !u && ii && Ki ? o : ee.left, Ct = u ? A(_, he, "after") : a), f(Qe, G.top, vt - Qe, G.bottom), G.bottom < ee.top && f(o, G.bottom, null, ee.top), f(Pe, ee.top, Ct - Pe, ee.bottom);
      }
      (!L || ni(G, L) < 0) && (L = G), ni(ee, L) < 0 && (L = ee), (!w || ni(G, w) < 0) && (w = G), ni(ee, w) < 0 && (w = ee);
    }), { start: L, end: w };
  }
  let d = t.from(), c = t.to();
  if (d.line == c.line)
    h(d.line, d.ch, c.ch);
  else {
    let p = v(r, d.line), m = v(r, c.line), g = ge(p) == ge(m), b = h(d.line, d.ch, g ? p.text.length + 1 : null).end, y = h(c.line, g ? 0 : null, c.ch).start;
    g && (b.top < y.top - 2 ? (f(b.right, b.top, null, b.bottom), f(o, y.top, y.left, y.bottom)) : f(b.right, b.top, y.left - b.right, b.bottom)), b.bottom < y.top && f(o, b.bottom, null, y.top);
  }
  i.appendChild(n);
}
function Bl(e) {
  if (!e.state.focused)
    return;
  let t = e.display;
  clearInterval(t.blinker);
  let i = !0;
  t.cursorDiv.style.visibility = "", e.options.cursorBlinkRate > 0 ? t.blinker = setInterval(() => {
    e.hasFocus() || bt(e), t.cursorDiv.style.visibility = (i = !i) ? "" : "hidden";
  }, e.options.cursorBlinkRate) : e.options.cursorBlinkRate < 0 && (t.cursorDiv.style.visibility = "hidden");
}
function Wn(e) {
  e.hasFocus() || (e.display.input.focus(), e.state.focused || Gl(e));
}
function zl(e) {
  e.state.delayingBlurEvent = !0, setTimeout(() => {
    e.state.delayingBlurEvent && (e.state.delayingBlurEvent = !1, e.state.focused && bt(e));
  }, 100);
}
function Gl(e, t) {
  e.state.delayingBlurEvent && !e.state.draggingText && (e.state.delayingBlurEvent = !1), e.options.readOnly != "nocursor" && (e.state.focused || (E(e, "focus", e, t), e.state.focused = !0, $e(e.display.wrapper, "CodeMirror-focused"), !e.curOp && e.display.selForContextMenu != e.doc.sel && (e.display.input.reset(), $ && setTimeout(() => e.display.input.reset(!0), 20)), e.display.input.receivedFocus()), Bl(e));
}
function bt(e, t) {
  e.state.delayingBlurEvent || (e.state.focused && (E(e, "blur", e, t), e.state.focused = !1, Xe(e.display.wrapper, "CodeMirror-focused")), clearInterval(e.display.blinker), setTimeout(() => {
    e.state.focused || (e.display.shift = !1);
  }, 150));
}
function Ri(e) {
  let t = e.display, i = t.lineDiv.offsetTop, l = Math.max(0, t.scroller.getBoundingClientRect().top), r = t.lineDiv.getBoundingClientRect().top, n = 0;
  for (let s = 0; s < t.view.length; s++) {
    let o = t.view[s], a = e.options.lineWrapping, u, f = 0;
    if (o.hidden)
      continue;
    if (r += o.line.height, N && F < 8) {
      let d = o.node.offsetTop + o.node.offsetHeight;
      u = d - i, i = d;
    } else {
      let d = o.node.getBoundingClientRect();
      u = d.bottom - d.top, !a && o.text.firstChild && (f = o.text.firstChild.getBoundingClientRect().right - d.left - 1);
    }
    let h = o.line.height - u;
    if ((h > 5e-3 || h < -5e-3) && (r < l && (n -= h), pe(o.line, u), xr(o.line), o.rest))
      for (let d = 0; d < o.rest.length; d++)
        xr(o.rest[d]);
    if (f > e.display.sizerWidth) {
      let d = Math.ceil(f / mt(e.display));
      d > e.display.maxLineLength && (e.display.maxLineLength = d, e.display.maxLine = o.line, e.display.maxLineChanged = !0);
    }
  }
  Math.abs(n) > 2 && (t.scroller.scrollTop += n);
}
function xr(e) {
  if (e.widgets)
    for (let t = 0; t < e.widgets.length; ++t) {
      let i = e.widgets[t], l = i.node.parentNode;
      l && (i.height = l.offsetHeight);
    }
}
function wi(e, t, i) {
  let l = i && i.top != null ? Math.max(0, i.top) : e.scroller.scrollTop;
  l = Math.floor(l - Ei(e));
  let r = i && i.bottom != null ? i.bottom : l + e.wrapper.clientHeight, n = Ie(t, l), s = Ie(t, r);
  if (i && i.ensure) {
    let o = i.ensure.from.line, a = i.ensure.to.line;
    o < n ? (n = o, s = Ie(t, Ce(v(t, o)) + e.wrapper.clientHeight)) : Math.min(a, t.lastLine()) >= s && (n = Ie(t, Ce(v(t, a)) - e.wrapper.clientHeight), s = a);
  }
  return { from: n, to: Math.max(s, n + 1) };
}
function Do(e, t) {
  if (R(e, "scrollCursorIntoView"))
    return;
  let i = e.display, l = i.sizer.getBoundingClientRect(), r = null;
  if (t.top + l.top < 0 ? r = !0 : t.bottom + l.top > (window.innerHeight || document.documentElement.clientHeight) && (r = !1), r != null && !ks) {
    let n = C("div", "​", null, `position: absolute;
                         top: ${t.top - i.viewOffset - Ei(e.display)}px;
                         height: ${t.bottom - t.top + ye(e) + i.barHeight}px;
                         left: ${t.left}px; width: ${Math.max(2, t.right - t.left)}px;`);
    e.display.lineSpace.appendChild(n), n.scrollIntoView(r), e.display.lineSpace.removeChild(n);
  }
}
function Oo(e, t, i, l) {
  l == null && (l = 0);
  let r;
  !e.options.lineWrapping && t == i && (i = t.sticky == "before" ? x(t.line, t.ch + 1, "before") : t, t = t.ch ? x(t.line, t.sticky == "before" ? t.ch - 1 : t.ch, "after") : t);
  for (let n = 0; n < 5; n++) {
    let s = !1, o = ae(e, t), a = !i || i == t ? o : ae(e, i);
    r = {
      left: Math.min(o.left, a.left),
      top: Math.min(o.top, a.top) - l,
      right: Math.max(o.left, a.left),
      bottom: Math.max(o.bottom, a.bottom) + l
    };
    let u = Ul(e, r), f = e.doc.scrollTop, h = e.doc.scrollLeft;
    if (u.scrollTop != null && (Vt(e, u.scrollTop), Math.abs(e.doc.scrollTop - f) > 1 && (s = !0)), u.scrollLeft != null && (je(e, u.scrollLeft), Math.abs(e.doc.scrollLeft - h) > 1 && (s = !0)), !s)
      break;
  }
  return r;
}
function Wo(e, t) {
  let i = Ul(e, t);
  i.scrollTop != null && Vt(e, i.scrollTop), i.scrollLeft != null && je(e, i.scrollLeft);
}
function Ul(e, t) {
  let i = e.display, l = ht(e.display);
  t.top < 0 && (t.top = 0);
  let r = e.curOp && e.curOp.scrollTop != null ? e.curOp.scrollTop : i.scroller.scrollTop, n = Wl(e), s = {};
  t.bottom - t.top > n && (t.bottom = t.top + n);
  let o = e.doc.height + Ol(i), a = t.top < l, u = t.bottom > o - l;
  if (t.top < r)
    s.scrollTop = a ? 0 : t.top;
  else if (t.bottom > r + n) {
    let p = Math.min(t.top, (u ? o : t.bottom) - n);
    p != r && (s.scrollTop = p);
  }
  let f = e.options.fixedGutter ? 0 : i.gutters.offsetWidth, h = e.curOp && e.curOp.scrollLeft != null ? e.curOp.scrollLeft : i.scroller.scrollLeft - f, d = Ye(e) - i.gutters.offsetWidth, c = t.right - t.left > d;
  return c && (t.right = t.left + d), t.left < 10 ? s.scrollLeft = 0 : t.left < h ? s.scrollLeft = Math.max(0, t.left + f - (c ? 0 : 10)) : t.right > d + h - 3 && (s.scrollLeft = t.right + (c ? 0 : 10) - d), s;
}
function Kl(e, t) {
  t != null && (Bi(e), e.curOp.scrollTop = (e.curOp.scrollTop == null ? e.doc.scrollTop : e.curOp.scrollTop) + t);
}
function xt(e) {
  Bi(e);
  let t = e.getCursor();
  e.curOp.scrollToPos = { from: t, to: t, margin: e.options.cursorScrollMargin };
}
function Wt(e, t, i) {
  (t != null || i != null) && Bi(e), t != null && (e.curOp.scrollLeft = t), i != null && (e.curOp.scrollTop = i);
}
function Ho(e, t) {
  Bi(e), e.curOp.scrollToPos = t;
}
function Bi(e) {
  let t = e.curOp.scrollToPos;
  if (t) {
    e.curOp.scrollToPos = null;
    let i = mr(e, t.from), l = mr(e, t.to);
    Hn(e, i, l, t.margin);
  }
}
function Hn(e, t, i, l) {
  let r = Ul(e, {
    left: Math.min(t.left, i.left),
    top: Math.min(t.top, i.top) - l,
    right: Math.max(t.right, i.right),
    bottom: Math.max(t.bottom, i.bottom) + l
  });
  Wt(e, r.scrollLeft, r.scrollTop);
}
function Vt(e, t) {
  Math.abs(e.doc.scrollTop - t) < 2 || (we || ol(e, { top: t }), Fn(e, t, !0), we && ol(e), ei(e, 100));
}
function Fn(e, t, i) {
  t = Math.max(0, Math.min(e.display.scroller.scrollHeight - e.display.scroller.clientHeight, t)), !(e.display.scroller.scrollTop == t && !i) && (e.doc.scrollTop = t, e.display.scrollbars.setScrollTop(t), e.display.scroller.scrollTop != t && (e.display.scroller.scrollTop = t));
}
function je(e, t, i, l) {
  t = Math.max(0, Math.min(t, e.display.scroller.scrollWidth - e.display.scroller.clientWidth)), !((i ? t == e.doc.scrollLeft : Math.abs(e.doc.scrollLeft - t) < 2) && !l) && (e.doc.scrollLeft = t, Bn(e), e.display.scroller.scrollLeft != t && (e.display.scroller.scrollLeft = t), e.display.scrollbars.setScrollLeft(t));
}
function jt(e) {
  let t = e.display, i = t.gutters.offsetWidth, l = Math.round(e.doc.height + Ol(e.display));
  return {
    clientHeight: t.scroller.clientHeight,
    viewHeight: t.wrapper.clientHeight,
    scrollWidth: t.scroller.scrollWidth,
    clientWidth: t.scroller.clientWidth,
    viewWidth: t.wrapper.clientWidth,
    barLeft: e.options.fixedGutter ? i : 0,
    docHeight: l,
    scrollHeight: l + ye(e) + t.barHeight,
    nativeBarWidth: t.nativeBarWidth,
    gutterWidth: i
  };
}
class Fo {
  constructor(t, i, l) {
    this.cm = l;
    let r = this.vert = C("div", [C("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar"), n = this.horiz = C("div", [C("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
    r.tabIndex = n.tabIndex = -1, t(r), t(n), S(r, "scroll", () => {
      r.clientHeight && i(r.scrollTop, "vertical");
    }), S(n, "scroll", () => {
      n.clientWidth && i(n.scrollLeft, "horizontal");
    }), this.checkedZeroWidth = !1, N && F < 8 && (this.horiz.style.minHeight = this.vert.style.minWidth = "18px");
  }
  update(t) {
    let i = t.scrollWidth > t.clientWidth + 1, l = t.scrollHeight > t.clientHeight + 1, r = t.nativeBarWidth;
    if (l) {
      this.vert.style.display = "block", this.vert.style.bottom = i ? r + "px" : "0";
      let n = t.viewHeight - (i ? r : 0);
      this.vert.firstChild.style.height = Math.max(0, t.scrollHeight - t.clientHeight + n) + "px";
    } else
      this.vert.style.display = "", this.vert.firstChild.style.height = "0";
    if (i) {
      this.horiz.style.display = "block", this.horiz.style.right = l ? r + "px" : "0", this.horiz.style.left = t.barLeft + "px";
      let n = t.viewWidth - t.barLeft - (l ? r : 0);
      this.horiz.firstChild.style.width = Math.max(0, t.scrollWidth - t.clientWidth + n) + "px";
    } else
      this.horiz.style.display = "", this.horiz.firstChild.style.width = "0";
    return !this.checkedZeroWidth && t.clientHeight > 0 && (r == 0 && this.zeroWidthHack(), this.checkedZeroWidth = !0), { right: l ? r : 0, bottom: i ? r : 0 };
  }
  setScrollLeft(t) {
    this.horiz.scrollLeft != t && (this.horiz.scrollLeft = t), this.disableHoriz && this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz");
  }
  setScrollTop(t) {
    this.vert.scrollTop != t && (this.vert.scrollTop = t), this.disableVert && this.enableZeroWidthBar(this.vert, this.disableVert, "vert");
  }
  zeroWidthHack() {
    let t = ne && !Ls ? "12px" : "18px";
    this.horiz.style.height = this.vert.style.width = t, this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none", this.disableHoriz = new ft(), this.disableVert = new ft();
  }
  enableZeroWidthBar(t, i, l) {
    t.style.pointerEvents = "auto";
    function r() {
      let n = t.getBoundingClientRect();
      (l == "vert" ? document.elementFromPoint(n.right - 1, (n.top + n.bottom) / 2) : document.elementFromPoint((n.right + n.left) / 2, n.bottom - 1)) != t ? t.style.pointerEvents = "none" : i.set(1e3, r);
    }
    i.set(1e3, r);
  }
  clear() {
    let t = this.horiz.parentNode;
    t.removeChild(this.horiz), t.removeChild(this.vert);
  }
}
class Po {
  update() {
    return { bottom: 0, right: 0 };
  }
  setScrollLeft() {
  }
  setScrollTop() {
  }
  clear() {
  }
}
function dt(e, t) {
  t || (t = jt(e));
  let i = e.display.barWidth, l = e.display.barHeight;
  wr(e, t);
  for (let r = 0; r < 4 && i != e.display.barWidth || l != e.display.barHeight; r++)
    i != e.display.barWidth && e.options.lineWrapping && Ri(e), wr(e, jt(e)), i = e.display.barWidth, l = e.display.barHeight;
}
function wr(e, t) {
  let i = e.display, l = i.scrollbars.update(t);
  i.sizer.style.paddingRight = (i.barWidth = l.right) + "px", i.sizer.style.paddingBottom = (i.barHeight = l.bottom) + "px", i.heightForcer.style.borderBottom = l.bottom + "px solid transparent", l.right && l.bottom ? (i.scrollbarFiller.style.display = "block", i.scrollbarFiller.style.height = l.bottom + "px", i.scrollbarFiller.style.width = l.right + "px") : i.scrollbarFiller.style.display = "", l.bottom && e.options.coverGutterNextToScrollbar && e.options.fixedGutter ? (i.gutterFiller.style.display = "block", i.gutterFiller.style.height = l.bottom + "px", i.gutterFiller.style.width = t.gutterWidth + "px") : i.gutterFiller.style.display = "";
}
let Pn = { native: Fo, null: Po };
function En(e) {
  e.display.scrollbars && (e.display.scrollbars.clear(), e.display.scrollbars.addClass && Xe(e.display.wrapper, e.display.scrollbars.addClass)), e.display.scrollbars = new Pn[e.options.scrollbarStyle]((t) => {
    e.display.wrapper.insertBefore(t, e.display.scrollbarFiller), S(t, "mousedown", () => {
      e.state.focused && setTimeout(() => e.display.input.focus(), 0);
    }), t.setAttribute("cm-not-content", "true");
  }, (t, i) => {
    i == "horizontal" ? je(e, t) : Vt(e, t);
  }, e), e.display.scrollbars.addClass && $e(e.display.wrapper, e.display.scrollbars.addClass);
}
let Eo = 0;
function qe(e) {
  e.curOp = {
    cm: e,
    viewChanged: !1,
    // Flag that indicates that lines might need to be redrawn
    startHeight: e.doc.height,
    // Used to detect need to update scrollbar
    forceUpdate: !1,
    // Used to force a redraw
    updateInput: 0,
    // Whether to reset the input textarea
    typing: !1,
    // Whether this reset should be careful to leave existing text (for compositing)
    changeObjs: null,
    // Accumulated changes, for firing change events
    cursorActivityHandlers: null,
    // Set of handlers to fire cursorActivity on
    cursorActivityCalled: 0,
    // Tracks which cursorActivity handlers have been called already
    selectionChanged: !1,
    // Whether the selection needs to be redrawn
    updateMaxLine: !1,
    // Set when the widest line needs to be determined anew
    scrollLeft: null,
    scrollTop: null,
    // Intermediate scroll position, not pushed to DOM yet
    scrollToPos: null,
    // Used to scroll to a specific position
    focus: !1,
    id: ++Eo,
    // Unique ID
    markArrays: null
    // Used by addMarkedSpan
  }, fo(e.curOp);
}
function Ze(e) {
  let t = e.curOp;
  t && co(t, (i) => {
    for (let l = 0; l < i.ops.length; l++)
      i.ops[l].cm.curOp = null;
    Io(i);
  });
}
function Io(e) {
  let t = e.ops;
  for (let i = 0; i < t.length; i++)
    Ro(t[i]);
  for (let i = 0; i < t.length; i++)
    Bo(t[i]);
  for (let i = 0; i < t.length; i++)
    zo(t[i]);
  for (let i = 0; i < t.length; i++)
    Go(t[i]);
  for (let i = 0; i < t.length; i++)
    Uo(t[i]);
}
function Ro(e) {
  let t = e.cm, i = t.display;
  _o(t), e.updateMaxLine && Al(t), e.mustUpdate = e.viewChanged || e.forceUpdate || e.scrollTop != null || e.scrollToPos && (e.scrollToPos.from.line < i.viewFrom || e.scrollToPos.to.line >= i.viewTo) || i.maxLineChanged && t.options.lineWrapping, e.update = e.mustUpdate && new In(t, e.mustUpdate && { top: e.scrollTop, ensure: e.scrollToPos }, e.forceUpdate);
}
function Bo(e) {
  e.updatedDisplay = e.mustUpdate && _l(e.cm, e.update);
}
function zo(e) {
  let t = e.cm, i = t.display;
  e.updatedDisplay && Ri(t), e.barMeasure = jt(t), i.maxLineChanged && !t.options.lineWrapping && (e.adjustWidthTo = wn(t, i.maxLine, i.maxLine.text.length).left + 3, t.display.sizerWidth = e.adjustWidthTo, e.barMeasure.scrollWidth = Math.max(i.scroller.clientWidth, i.sizer.offsetLeft + e.adjustWidthTo + ye(t) + t.display.barWidth), e.maxScrollLeft = Math.max(0, i.sizer.offsetLeft + e.adjustWidthTo - Ye(t))), (e.updatedDisplay || e.selectionChanged) && (e.preparedSelection = i.input.prepareSelection());
}
function Go(e) {
  let t = e.cm;
  e.adjustWidthTo != null && (t.display.sizer.style.minWidth = e.adjustWidthTo + "px", e.maxScrollLeft < t.doc.scrollLeft && je(t, Math.min(t.display.scroller.scrollLeft, e.maxScrollLeft), !0), t.display.maxLineChanged = !1);
  let i = e.focus && e.focus == re();
  e.preparedSelection && t.display.input.showSelection(e.preparedSelection, i), (e.updatedDisplay || e.startHeight != t.doc.height) && dt(t, e.barMeasure), e.updatedDisplay && $l(t, e.barMeasure), e.selectionChanged && Bl(t), t.state.focused && e.updateInput && t.display.input.reset(e.typing), i && Wn(e.cm);
}
function Uo(e) {
  let t = e.cm, i = t.display, l = t.doc;
  if (e.updatedDisplay && Rn(t, e.update), i.wheelStartX != null && (e.scrollTop != null || e.scrollLeft != null || e.scrollToPos) && (i.wheelStartX = i.wheelStartY = null), e.scrollTop != null && Fn(t, e.scrollTop, e.forceScroll), e.scrollLeft != null && je(t, e.scrollLeft, !0, !0), e.scrollToPos) {
    let s = Oo(
      t,
      k(l, e.scrollToPos.from),
      k(l, e.scrollToPos.to),
      e.scrollToPos.margin
    );
    Do(t, s);
  }
  let r = e.maybeHiddenMarkers, n = e.maybeUnhiddenMarkers;
  if (r)
    for (let s = 0; s < r.length; ++s)
      r[s].lines.length || E(r[s], "hide");
  if (n)
    for (let s = 0; s < n.length; ++s)
      n[s].lines.length && E(n[s], "unhide");
  i.wrapper.offsetHeight && (l.scrollTop = t.display.scroller.scrollTop), e.changeObjs && E(t, "changes", t, e.changeObjs), e.update && e.update.finish();
}
function J(e, t) {
  if (e.curOp)
    return t();
  qe(e);
  try {
    return t();
  } finally {
    Ze(e);
  }
}
function B(e, t) {
  return function() {
    if (e.curOp)
      return t.apply(e, arguments);
    qe(e);
    try {
      return t.apply(e, arguments);
    } finally {
      Ze(e);
    }
  };
}
function X(e) {
  return function() {
    if (this.curOp)
      return e.apply(this, arguments);
    qe(this);
    try {
      return e.apply(this, arguments);
    } finally {
      Ze(this);
    }
  };
}
function I(e) {
  return function() {
    let t = this.cm;
    if (!t || t.curOp)
      return e.apply(this, arguments);
    qe(t);
    try {
      return e.apply(this, arguments);
    } finally {
      Ze(t);
    }
  };
}
function ei(e, t) {
  e.doc.highlightFrontier < e.display.viewTo && e.state.highlight.set(t, yl(Ko, e));
}
function Ko(e) {
  let t = e.doc;
  if (t.highlightFrontier >= e.display.viewTo)
    return;
  let i = +/* @__PURE__ */ new Date() + e.options.workTime, l = Jt(e, t.highlightFrontier), r = [];
  t.iter(l.line, Math.min(t.first + t.size, e.display.viewTo + 500), (n) => {
    if (l.line >= e.display.viewFrom) {
      let s = n.styles, o = n.text.length > e.options.maxHighlightLength ? Be(t.mode, l.state) : null, a = ln(e, n, l, !0);
      o && (l.state = o), n.styles = a.styles;
      let u = n.styleClasses, f = a.classes;
      f ? n.styleClasses = f : u && (n.styleClasses = null);
      let h = !s || s.length != n.styles.length || u != f && (!u || !f || u.bgClass != f.bgClass || u.textClass != f.textClass);
      for (let d = 0; !h && d < s.length; ++d)
        h = s[d] != n.styles[d];
      h && r.push(l.line), n.stateAfter = l.save(), l.nextLine();
    } else
      n.text.length <= e.options.maxHighlightLength && kl(e, n.text, l), n.stateAfter = l.line % 5 == 0 ? l.save() : null, l.nextLine();
    if (+/* @__PURE__ */ new Date() > i)
      return ei(e, e.options.workDelay), !0;
  }), t.highlightFrontier = l.line, t.modeFrontier = Math.max(t.modeFrontier, l.line), r.length && J(e, () => {
    for (let n = 0; n < r.length; n++)
      Fe(e, r[n], "text");
  });
}
class In {
  constructor(t, i, l) {
    let r = t.display;
    this.viewport = i, this.visible = wi(r, t.doc, i), this.editorIsHidden = !r.wrapper.offsetWidth, this.wrapperHeight = r.wrapper.clientHeight, this.wrapperWidth = r.wrapper.clientWidth, this.oldDisplayWidth = Ye(t), this.force = l, this.dims = El(t), this.events = [];
  }
  signal(t, i) {
    se(t, i) && this.events.push(arguments);
  }
  finish() {
    for (let t = 0; t < this.events.length; t++)
      E.apply(null, this.events[t]);
  }
}
function _o(e) {
  let t = e.display;
  !t.scrollbarsClipped && t.scroller.offsetWidth && (t.nativeBarWidth = t.scroller.offsetWidth - t.scroller.clientWidth, t.heightForcer.style.height = ye(e) + "px", t.sizer.style.marginBottom = -t.nativeBarWidth + "px", t.sizer.style.borderRightWidth = ye(e) + "px", t.scrollbarsClipped = !0);
}
function Xo(e) {
  if (e.hasFocus())
    return null;
  let t = re();
  if (!t || !Ae(e.display.lineDiv, t))
    return null;
  let i = { activeElt: t };
  if (window.getSelection) {
    let l = window.getSelection();
    l.anchorNode && l.extend && Ae(e.display.lineDiv, l.anchorNode) && (i.anchorNode = l.anchorNode, i.anchorOffset = l.anchorOffset, i.focusNode = l.focusNode, i.focusOffset = l.focusOffset);
  }
  return i;
}
function $o(e) {
  if (!(!e || !e.activeElt || e.activeElt == re()) && (e.activeElt.focus(), !/^(INPUT|TEXTAREA)$/.test(e.activeElt.nodeName) && e.anchorNode && Ae(document.body, e.anchorNode) && Ae(document.body, e.focusNode))) {
    let t = window.getSelection(), i = document.createRange();
    i.setEnd(e.anchorNode, e.anchorOffset), i.collapse(!1), t.removeAllRanges(), t.addRange(i), t.extend(e.focusNode, e.focusOffset);
  }
}
function _l(e, t) {
  let i = e.display, l = e.doc;
  if (t.editorIsHidden)
    return Te(e), !1;
  if (!t.force && t.visible.from >= i.viewFrom && t.visible.to <= i.viewTo && (i.updateLineNumbers == null || i.updateLineNumbers >= i.viewTo) && i.renderedView == i.view && br(e) == 0)
    return !1;
  zn(e) && (Te(e), t.dims = El(e));
  let r = l.first + l.size, n = Math.max(t.visible.from - e.options.viewportMargin, l.first), s = Math.min(r, t.visible.to + e.options.viewportMargin);
  i.viewFrom < n && n - i.viewFrom < 20 && (n = Math.max(l.first, i.viewFrom)), i.viewTo > s && i.viewTo - s < 20 && (s = Math.min(r, i.viewTo)), ve && (n = Nl(e.doc, n), s = hn(e.doc, s));
  let o = n != i.viewFrom || s != i.viewTo || i.lastWrapHeight != t.wrapperHeight || i.lastWrapWidth != t.wrapperWidth;
  No(e, n, s), i.viewOffset = Ce(v(e.doc, i.viewFrom)), e.display.mover.style.top = i.viewOffset + "px";
  let a = br(e);
  if (!o && a == 0 && !t.force && i.renderedView == i.view && (i.updateLineNumbers == null || i.updateLineNumbers >= i.viewTo))
    return !1;
  let u = Xo(e);
  return a > 4 && (i.lineDiv.style.display = "none"), Yo(e, i.updateLineNumbers, t.dims), a > 4 && (i.lineDiv.style.display = ""), i.renderedView = i.view, $o(u), Ne(i.cursorDiv), Ne(i.selectionDiv), i.gutters.style.height = i.sizer.style.minHeight = 0, o && (i.lastWrapHeight = t.wrapperHeight, i.lastWrapWidth = t.wrapperWidth, ei(e, 400)), i.updateLineNumbers = null, !0;
}
function Rn(e, t) {
  let i = t.viewport;
  for (let l = !0; ; l = !1) {
    if (!l || !e.options.lineWrapping || t.oldDisplayWidth == Ye(e)) {
      if (i && i.top != null && (i = { top: Math.min(e.doc.height + Ol(e.display) - Wl(e), i.top) }), t.visible = wi(e.display, e.doc, i), t.visible.from >= e.display.viewFrom && t.visible.to <= e.display.viewTo)
        break;
    } else
      l && (t.visible = wi(e.display, e.doc, i));
    if (!_l(e, t))
      break;
    Ri(e);
    let r = jt(e);
    Ot(e), dt(e, r), $l(e, r), t.force = !1;
  }
  t.signal(e, "update", e), (e.display.viewFrom != e.display.reportedViewFrom || e.display.viewTo != e.display.reportedViewTo) && (t.signal(e, "viewportChange", e, e.display.viewFrom, e.display.viewTo), e.display.reportedViewFrom = e.display.viewFrom, e.display.reportedViewTo = e.display.viewTo);
}
function ol(e, t) {
  let i = new In(e, t);
  if (_l(e, i)) {
    Ri(e), Rn(e, i);
    let l = jt(e);
    Ot(e), dt(e, l), $l(e, l), i.finish();
  }
}
function Yo(e, t, i) {
  let l = e.display, r = e.options.lineNumbers, n = l.lineDiv, s = n.firstChild;
  function o(f) {
    let h = f.nextSibling;
    return $ && ne && e.display.currentWheelTarget == f ? f.style.display = "none" : f.parentNode.removeChild(f), h;
  }
  let a = l.view, u = l.viewFrom;
  for (let f = 0; f < a.length; f++) {
    let h = a[f];
    if (!h.hidden)
      if (!h.node || h.node.parentNode != n) {
        let d = bo(e, h, u, i);
        n.insertBefore(d, s);
      } else {
        for (; s != h.node; )
          s = o(s);
        let d = r && t != null && t <= u && h.lineNumber;
        h.changes && (K(h.changes, "gutter") > -1 && (d = !1), pn(e, h, u, i)), d && (Ne(h.lineNumber), h.lineNumber.appendChild(document.createTextNode(Ll(e.options, u)))), s = h.node.nextSibling;
      }
    u += h.size;
  }
  for (; s; )
    s = o(s);
}
function Xl(e) {
  let t = e.gutters.offsetWidth;
  e.sizer.style.marginLeft = t + "px", z(e, "gutterChanged", e);
}
function $l(e, t) {
  e.display.sizer.style.minHeight = t.docHeight + "px", e.display.heightForcer.style.top = t.docHeight + "px", e.display.gutters.style.height = t.docHeight + e.display.barHeight + ye(e) + "px";
}
function Bn(e) {
  let t = e.display, i = t.view;
  if (!t.alignWidgets && (!t.gutters.firstChild || !e.options.fixedGutter))
    return;
  let l = Il(t) - t.scroller.scrollLeft + e.doc.scrollLeft, r = t.gutters.offsetWidth, n = l + "px";
  for (let s = 0; s < i.length; s++)
    if (!i[s].hidden) {
      e.options.fixedGutter && (i[s].gutter && (i[s].gutter.style.left = n), i[s].gutterBackground && (i[s].gutterBackground.style.left = n));
      let o = i[s].alignable;
      if (o)
        for (let a = 0; a < o.length; a++)
          o[a].style.left = n;
    }
  e.options.fixedGutter && (t.gutters.style.left = l + r + "px");
}
function zn(e) {
  if (!e.options.lineNumbers)
    return !1;
  let t = e.doc, i = Ll(e.options, t.first + t.size - 1), l = e.display;
  if (i.length != l.lineNumChars) {
    let r = l.measure.appendChild(C(
      "div",
      [C("div", i)],
      "CodeMirror-linenumber CodeMirror-gutter-elt"
    )), n = r.firstChild.offsetWidth, s = r.offsetWidth - n;
    return l.lineGutter.style.width = "", l.lineNumInnerWidth = Math.max(n, l.lineGutter.offsetWidth - s) + 1, l.lineNumWidth = l.lineNumInnerWidth + s, l.lineNumChars = l.lineNumInnerWidth ? i.length : -1, l.lineGutter.style.width = l.lineNumWidth + "px", Xl(e.display), !0;
  }
  return !1;
}
function al(e, t) {
  let i = [], l = !1;
  for (let r = 0; r < e.length; r++) {
    let n = e[r], s = null;
    if (typeof n != "string" && (s = n.style, n = n.className), n == "CodeMirror-linenumbers")
      if (t)
        l = !0;
      else
        continue;
    i.push({ className: n, style: s });
  }
  return t && !l && i.push({ className: "CodeMirror-linenumbers", style: null }), i;
}
function Gn(e) {
  let t = e.gutters, i = e.gutterSpecs;
  Ne(t), e.lineGutter = null;
  for (let l = 0; l < i.length; ++l) {
    let { className: r, style: n } = i[l], s = t.appendChild(C("div", null, "CodeMirror-gutter " + r));
    n && (s.style.cssText = n), r == "CodeMirror-linenumbers" && (e.lineGutter = s, s.style.width = (e.lineNumWidth || 1) + "px");
  }
  t.style.display = i.length ? "" : "none", Xl(e);
}
function St(e) {
  Gn(e.display), q(e), Bn(e);
}
function jo(e, t, i, l) {
  let r = this;
  this.input = i, r.scrollbarFiller = C("div", null, "CodeMirror-scrollbar-filler"), r.scrollbarFiller.setAttribute("cm-not-content", "true"), r.gutterFiller = C("div", null, "CodeMirror-gutter-filler"), r.gutterFiller.setAttribute("cm-not-content", "true"), r.lineDiv = rt("div", null, "CodeMirror-code"), r.selectionDiv = C("div", null, null, "position: relative; z-index: 1"), r.cursorDiv = C("div", null, "CodeMirror-cursors"), r.measure = C("div", null, "CodeMirror-measure"), r.lineMeasure = C("div", null, "CodeMirror-measure"), r.lineSpace = rt(
    "div",
    [r.measure, r.lineMeasure, r.selectionDiv, r.cursorDiv, r.lineDiv],
    null,
    "position: relative; outline: none"
  );
  let n = rt("div", [r.lineSpace], "CodeMirror-lines");
  r.mover = C("div", [n], null, "position: relative"), r.sizer = C("div", [r.mover], "CodeMirror-sizer"), r.sizerWidth = null, r.heightForcer = C("div", null, null, "position: absolute; height: " + Yr + "px; width: 1px;"), r.gutters = C("div", null, "CodeMirror-gutters"), r.lineGutter = null, r.scroller = C("div", [r.sizer, r.heightForcer, r.gutters], "CodeMirror-scroll"), r.scroller.setAttribute("tabIndex", "-1"), r.wrapper = C("div", [r.scrollbarFiller, r.gutterFiller, r.scroller], "CodeMirror"), r.wrapper.setAttribute("translate", "no"), N && F < 8 && (r.gutters.style.zIndex = -1, r.scroller.style.paddingRight = 0), !$ && !(we && It) && (r.scroller.draggable = !0), e && (e.appendChild ? e.appendChild(r.wrapper) : e(r.wrapper)), r.viewFrom = r.viewTo = t.first, r.reportedViewFrom = r.reportedViewTo = t.first, r.view = [], r.renderedView = null, r.externalMeasured = null, r.viewOffset = 0, r.lastWrapHeight = r.lastWrapWidth = 0, r.updateLineNumbers = null, r.nativeBarWidth = r.barHeight = r.barWidth = 0, r.scrollbarsClipped = !1, r.lineNumWidth = r.lineNumInnerWidth = r.lineNumChars = null, r.alignWidgets = !1, r.cachedCharWidth = r.cachedTextHeight = r.cachedPaddingH = null, r.maxLine = null, r.maxLineLength = 0, r.maxLineChanged = !1, r.wheelDX = r.wheelDY = r.wheelStartX = r.wheelStartY = null, r.shift = !1, r.selForContextMenu = null, r.activeTouch = null, r.gutterSpecs = al(l.gutters, l.lineNumbers), Gn(r), i.init(r);
}
let si = 0, be = null;
N ? be = -0.53 : we ? be = 15 : Ti ? be = -0.7 : Mi && (be = -1 / 3);
function Un(e) {
  let t = e.wheelDeltaX, i = e.wheelDeltaY;
  return t == null && e.detail && e.axis == e.HORIZONTAL_AXIS && (t = e.detail), i == null && e.detail && e.axis == e.VERTICAL_AXIS ? i = e.detail : i == null && (i = e.wheelDelta), { x: t, y: i };
}
function qo(e) {
  let t = Un(e);
  return t.x *= be, t.y *= be, t;
}
function vr(e, t) {
  let i = Un(t), l = i.x, r = i.y, n = be;
  event.deltaMode === 0 && (l = t.deltaX, r = t.deltaY, n = 1);
  let s = e.display, o = s.scroller, a = o.scrollWidth > o.clientWidth, u = o.scrollHeight > o.clientHeight;
  if (l && a || r && u) {
    if (r && ne && $) {
      e:
        for (let f = t.target, h = s.view; f != o; f = f.parentNode)
          for (let d = 0; d < h.length; d++)
            if (h[d].node == f) {
              e.display.currentWheelTarget = f;
              break e;
            }
    }
    if (l && !we && !fe && n != null) {
      r && u && Vt(e, Math.max(0, o.scrollTop + r * n)), je(e, Math.max(0, o.scrollLeft + l * n)), (!r || r && u) && j(t), s.wheelStartX = null;
      return;
    }
    if (r && n != null) {
      let f = r * n, h = e.doc.scrollTop, d = h + s.wrapper.clientHeight;
      f < 0 ? h = Math.max(0, h + f - 50) : d = Math.min(e.doc.height, d + f + 50), ol(e, { top: h, bottom: d });
    }
    si < 20 && t.deltaMode !== 0 && (s.wheelStartX == null ? (s.wheelStartX = o.scrollLeft, s.wheelStartY = o.scrollTop, s.wheelDX = l, s.wheelDY = r, setTimeout(() => {
      if (s.wheelStartX == null)
        return;
      let f = o.scrollLeft - s.wheelStartX, h = o.scrollTop - s.wheelStartY, d = h && s.wheelDY && h / s.wheelDY || f && s.wheelDX && f / s.wheelDX;
      s.wheelStartX = s.wheelStartY = null, d && (be = (be * si + d) / (si + 1), ++si);
    }, 200)) : (s.wheelDX += l, s.wheelDY += r));
  }
}
class ke {
  constructor(t, i) {
    this.ranges = t, this.primIndex = i;
  }
  primary() {
    return this.ranges[this.primIndex];
  }
  equals(t) {
    if (t == this)
      return !0;
    if (t.primIndex != this.primIndex || t.ranges.length != this.ranges.length)
      return !1;
    for (let i = 0; i < this.ranges.length; i++) {
      let l = this.ranges[i], r = t.ranges[i];
      if (!tl(l.anchor, r.anchor) || !tl(l.head, r.head))
        return !1;
    }
    return !0;
  }
  deepCopy() {
    let t = [];
    for (let i = 0; i < this.ranges.length; i++)
      t[i] = new H(il(this.ranges[i].anchor), il(this.ranges[i].head));
    return new ke(t, this.primIndex);
  }
  somethingSelected() {
    for (let t = 0; t < this.ranges.length; t++)
      if (!this.ranges[t].empty())
        return !0;
    return !1;
  }
  contains(t, i) {
    i || (i = t);
    for (let l = 0; l < this.ranges.length; l++) {
      let r = this.ranges[l];
      if (T(i, r.from()) >= 0 && T(t, r.to()) <= 0)
        return l;
    }
    return -1;
  }
}
class H {
  constructor(t, i) {
    this.anchor = t, this.head = i;
  }
  from() {
    return Hi(this.anchor, this.head);
  }
  to() {
    return Wi(this.anchor, this.head);
  }
  empty() {
    return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
  }
}
function ue(e, t, i) {
  let l = e && e.options.selectionsMayTouch, r = t[i];
  t.sort((n, s) => T(n.from(), s.from())), i = K(t, r);
  for (let n = 1; n < t.length; n++) {
    let s = t[n], o = t[n - 1], a = T(o.to(), s.from());
    if (l && !s.empty() ? a > 0 : a >= 0) {
      let u = Hi(o.from(), s.from()), f = Wi(o.to(), s.to()), h = o.empty() ? s.from() == s.head : o.from() == o.head;
      n <= i && --i, t.splice(--n, 2, new H(h ? f : u, h ? u : f));
    }
  }
  return new ke(t, i);
}
function Oe(e, t) {
  return new ke([new H(e, t || e)], 0);
}
function We(e) {
  return e.text ? x(
    e.from.line + e.text.length - 1,
    O(e.text).length + (e.text.length == 1 ? e.from.ch : 0)
  ) : e.to;
}
function Cr(e, t) {
  if (T(e, t.from) < 0)
    return e;
  if (T(e, t.to) <= 0)
    return We(t);
  let i = e.line + t.text.length - (t.to.line - t.from.line) - 1, l = e.ch;
  return e.line == t.to.line && (l += We(t).ch - t.to.ch), x(i, l);
}
function Yl(e, t) {
  let i = [];
  for (let l = 0; l < e.sel.ranges.length; l++) {
    let r = e.sel.ranges[l];
    i.push(new H(
      Cr(r.anchor, t),
      Cr(r.head, t)
    ));
  }
  return ue(e.cm, i, e.sel.primIndex);
}
function Sr(e, t, i) {
  return e.line == t.line ? x(i.line, e.ch - t.ch + i.ch) : x(i.line + (e.line - t.line), e.ch);
}
function Zo(e, t, i) {
  let l = [], r = x(e.first, 0), n = r;
  for (let s = 0; s < t.length; s++) {
    let o = t[s], a = Sr(o.from, r, n), u = Sr(We(o), r, n);
    if (r = o.to, n = u, i == "around") {
      let f = e.sel.ranges[s], h = T(f.head, f.anchor) < 0;
      l[s] = new H(h ? u : a, h ? a : u);
    } else
      l[s] = new H(a, a);
  }
  return new ke(l, e.sel.primIndex);
}
function ul(e) {
  e.doc.mode = Cl(e.options, e.doc.modeOption), Mt(e);
}
function Mt(e) {
  e.doc.iter((t) => {
    t.stateAfter && (t.stateAfter = null), t.styles && (t.styles = null);
  }), e.doc.modeFrontier = e.doc.highlightFrontier = e.doc.first, ei(e, 100), e.state.modeGen++, e.curOp && q(e);
}
function Kn(e, t) {
  return t.from.ch == 0 && t.to.ch == 0 && O(t.text) == "" && (!e.cm || e.cm.options.wholeLineUpdateBefore);
}
function jl(e, t, i, l) {
  function r(m) {
    return i ? i[m] : null;
  }
  function n(m, g, b) {
    to(m, g, b, l), z(m, "change", m, t);
  }
  function s(m, g) {
    let b = [];
    for (let y = m; y < g; ++y)
      b.push(new _t(u[y], r(y), l));
    return b;
  }
  let o = t.from, a = t.to, u = t.text, f = v(e, o.line), h = v(e, a.line), d = O(u), c = r(u.length - 1), p = a.line - o.line;
  if (t.full)
    e.insert(0, s(0, u.length)), e.remove(u.length, e.size - u.length);
  else if (Kn(e, t)) {
    let m = s(0, u.length - 1);
    n(h, h.text, c), p && e.remove(o.line, p), m.length && e.insert(o.line, m);
  } else if (f == h)
    if (u.length == 1)
      n(f, f.text.slice(0, o.ch) + d + f.text.slice(a.ch), c);
    else {
      let m = s(1, u.length - 1);
      m.push(new _t(d + f.text.slice(a.ch), c, l)), n(f, f.text.slice(0, o.ch) + u[0], r(0)), e.insert(o.line + 1, m);
    }
  else if (u.length == 1)
    n(f, f.text.slice(0, o.ch) + u[0] + h.text.slice(a.ch), r(0)), e.remove(o.line + 1, p);
  else {
    n(f, f.text.slice(0, o.ch) + u[0], r(0)), n(h, d + h.text.slice(a.ch), c);
    let m = s(1, u.length - 1);
    p > 1 && e.remove(o.line + 1, p - 1), e.insert(o.line + 1, m);
  }
  z(e, "change", e, t);
}
function Me(e, t, i) {
  function l(r, n, s) {
    if (r.linked)
      for (let o = 0; o < r.linked.length; ++o) {
        let a = r.linked[o];
        if (a.doc == n)
          continue;
        let u = s && a.sharedHist;
        i && !u || (t(a.doc, u), l(a.doc, r, u));
      }
  }
  l(e, null, !0);
}
function _n(e, t) {
  if (t.cm)
    throw new Error("This document is already in use.");
  e.doc = t, t.cm = e, Rl(e), ul(e), Xn(e), e.options.direction = t.direction, e.options.lineWrapping || Al(e), e.options.mode = t.modeOption, q(e);
}
function Xn(e) {
  (e.doc.direction == "rtl" ? $e : Xe)(e.display.lineDiv, "CodeMirror-rtl");
}
function Qo(e) {
  J(e, () => {
    Xn(e), q(e);
  });
}
function hi(e) {
  this.done = [], this.undone = [], this.undoDepth = e ? e.undoDepth : 1 / 0, this.lastModTime = this.lastSelTime = 0, this.lastOp = this.lastSelOp = null, this.lastOrigin = this.lastSelOrigin = null, this.generation = this.maxGeneration = e ? e.maxGeneration : 1;
}
function fl(e, t) {
  let i = { from: il(t.from), to: We(t), text: ze(e, t.from, t.to) };
  return Lr(e, i, t.from.line, t.to.line + 1), Me(e, (l) => Lr(l, i, t.from.line, t.to.line + 1), !0), i;
}
function $n(e) {
  for (; e.length && O(e).ranges; )
    e.pop();
}
function Jo(e, t) {
  if (t)
    return $n(e.done), O(e.done);
  if (e.done.length && !O(e.done).ranges)
    return O(e.done);
  if (e.done.length > 1 && !e.done[e.done.length - 2].ranges)
    return e.done.pop(), O(e.done);
}
function Yn(e, t, i, l) {
  let r = e.history;
  r.undone.length = 0;
  let n = +/* @__PURE__ */ new Date(), s, o;
  if ((r.lastOp == l || r.lastOrigin == t.origin && t.origin && (t.origin.charAt(0) == "+" && r.lastModTime > n - (e.cm ? e.cm.options.historyEventDelay : 500) || t.origin.charAt(0) == "*")) && (s = Jo(r, r.lastOp == l)))
    o = O(s.changes), T(t.from, t.to) == 0 && T(t.from, o.to) == 0 ? o.to = We(t) : s.changes.push(fl(e, t));
  else {
    let a = O(r.done);
    for ((!a || !a.ranges) && vi(e.sel, r.done), s = {
      changes: [fl(e, t)],
      generation: r.generation
    }, r.done.push(s); r.done.length > r.undoDepth; )
      r.done.shift(), r.done[0].ranges || r.done.shift();
  }
  r.done.push(i), r.generation = ++r.maxGeneration, r.lastModTime = r.lastSelTime = n, r.lastOp = r.lastSelOp = l, r.lastOrigin = r.lastSelOrigin = t.origin, o || E(e, "historyAdded");
}
function Vo(e, t, i, l) {
  let r = t.charAt(0);
  return r == "*" || r == "+" && i.ranges.length == l.ranges.length && i.somethingSelected() == l.somethingSelected() && /* @__PURE__ */ new Date() - e.history.lastSelTime <= (e.cm ? e.cm.options.historyEventDelay : 500);
}
function ea(e, t, i, l) {
  let r = e.history, n = l && l.origin;
  i == r.lastSelOp || n && r.lastSelOrigin == n && (r.lastModTime == r.lastSelTime && r.lastOrigin == n || Vo(e, n, O(r.done), t)) ? r.done[r.done.length - 1] = t : vi(t, r.done), r.lastSelTime = +/* @__PURE__ */ new Date(), r.lastSelOrigin = n, r.lastSelOp = i, l && l.clearRedo !== !1 && $n(r.undone);
}
function vi(e, t) {
  let i = O(t);
  i && i.ranges && i.equals(e) || t.push(e);
}
function Lr(e, t, i, l) {
  let r = t["spans_" + e.id], n = 0;
  e.iter(Math.max(e.first, i), Math.min(e.first + e.size, l), (s) => {
    s.markedSpans && ((r || (r = t["spans_" + e.id] = {}))[n] = s.markedSpans), ++n;
  });
}
function ta(e) {
  if (!e)
    return null;
  let t;
  for (let i = 0; i < e.length; ++i)
    e[i].marker.explicitlyCleared ? t || (t = e.slice(0, i)) : t && t.push(e[i]);
  return t ? t.length ? t : null : e;
}
function ia(e, t) {
  let i = t["spans_" + e.id];
  if (!i)
    return null;
  let l = [];
  for (let r = 0; r < t.text.length; ++r)
    l.push(ta(i[r]));
  return l;
}
function kr(e, t) {
  let i = ia(e, t), l = ll(e, t);
  if (!i)
    return l;
  if (!l)
    return i;
  for (let r = 0; r < i.length; ++r) {
    let n = i[r], s = l[r];
    if (n && s)
      e:
        for (let o = 0; o < s.length; ++o) {
          let a = s[o];
          for (let u = 0; u < n.length; ++u)
            if (n[u].marker == a.marker)
              continue e;
          n.push(a);
        }
    else
      s && (i[r] = s);
  }
  return i;
}
function Je(e, t, i) {
  let l = [];
  for (let n = 0; n < e.length; ++n) {
    let s = e[n];
    if (s.ranges) {
      l.push(i ? ke.prototype.deepCopy.call(s) : s);
      continue;
    }
    let o = s.changes, a = [];
    l.push({ changes: a });
    for (let u = 0; u < o.length; ++u) {
      let f = o[u], h;
      if (a.push({ from: f.from, to: f.to, text: f.text }), t)
        for (var r in f)
          (h = r.match(/^spans_(\d+)$/)) && K(t, Number(h[1])) > -1 && (O(a)[r] = f[r], delete f[r]);
    }
  }
  return l;
}
function ql(e, t, i, l) {
  if (l) {
    let r = e.anchor;
    if (i) {
      let n = T(t, r) < 0;
      n != T(i, r) < 0 ? (r = t, t = i) : n != T(t, i) < 0 && (t = i);
    }
    return new H(r, t);
  } else
    return new H(i || t, t);
}
function zi(e, t, i, l, r) {
  r == null && (r = e.cm && (e.cm.display.shift || e.extend)), U(e, new ke([ql(e.sel.primary(), t, i, r)], 0), l);
}
function Tr(e, t, i) {
  let l = [], r = e.cm && (e.cm.display.shift || e.extend);
  for (let s = 0; s < e.sel.ranges.length; s++)
    l[s] = ql(e.sel.ranges[s], t[s], null, r);
  let n = ue(e.cm, l, e.sel.primIndex);
  U(e, n, i);
}
function Zl(e, t, i, l) {
  let r = e.sel.ranges.slice(0);
  r[t] = i, U(e, ue(e.cm, r, e.sel.primIndex), l);
}
function Mr(e, t, i, l) {
  U(e, Oe(t, i), l);
}
function la(e, t, i) {
  let l = {
    ranges: t.ranges,
    update: function(r) {
      this.ranges = [];
      for (let n = 0; n < r.length; n++)
        this.ranges[n] = new H(
          k(e, r[n].anchor),
          k(e, r[n].head)
        );
    },
    origin: i && i.origin
  };
  return E(e, "beforeSelectionChange", e, l), e.cm && E(e.cm, "beforeSelectionChange", e.cm, l), l.ranges != t.ranges ? ue(e.cm, l.ranges, l.ranges.length - 1) : t;
}
function jn(e, t, i) {
  let l = e.history.done, r = O(l);
  r && r.ranges ? (l[l.length - 1] = t, Gi(e, t, i)) : U(e, t, i);
}
function U(e, t, i) {
  Gi(e, t, i), ea(e, e.sel, e.cm ? e.cm.curOp.id : NaN, i);
}
function Gi(e, t, i) {
  (se(e, "beforeSelectionChange") || e.cm && se(e.cm, "beforeSelectionChange")) && (t = la(e, t, i));
  let l = i && i.bias || (T(t.primary().head, e.sel.primary().head) < 0 ? -1 : 1);
  qn(e, Qn(e, t, l, !0)), !(i && i.scroll === !1) && e.cm && e.cm.getOption("readOnly") != "nocursor" && xt(e.cm);
}
function qn(e, t) {
  t.equals(e.sel) || (e.sel = t, e.cm && (e.cm.curOp.updateInput = 1, e.cm.curOp.selectionChanged = !0, Qr(e.cm)), z(e, "cursorActivity", e));
}
function Zn(e) {
  qn(e, Qn(e, e.sel, null, !1));
}
function Qn(e, t, i, l) {
  let r;
  for (let n = 0; n < t.ranges.length; n++) {
    let s = t.ranges[n], o = t.ranges.length == e.sel.ranges.length && e.sel.ranges[n], a = Ci(e, s.anchor, o && o.anchor, i, l), u = Ci(e, s.head, o && o.head, i, l);
    (r || a != s.anchor || u != s.head) && (r || (r = t.ranges.slice(0, n)), r[n] = new H(a, u));
  }
  return r ? ue(e.cm, r, t.primIndex) : t;
}
function it(e, t, i, l, r) {
  let n = v(e, t.line);
  if (n.markedSpans)
    for (let s = 0; s < n.markedSpans.length; ++s) {
      let o = n.markedSpans[s], a = o.marker, u = "selectLeft" in a ? !a.selectLeft : a.inclusiveLeft, f = "selectRight" in a ? !a.selectRight : a.inclusiveRight;
      if ((o.from == null || (u ? o.from <= t.ch : o.from < t.ch)) && (o.to == null || (f ? o.to >= t.ch : o.to > t.ch))) {
        if (r && (E(a, "beforeCursorEnter"), a.explicitlyCleared))
          if (n.markedSpans) {
            --s;
            continue;
          } else
            break;
        if (!a.atomic)
          continue;
        if (i) {
          let d = a.find(l < 0 ? 1 : -1), c;
          if ((l < 0 ? f : u) && (d = Nr(e, d, -l, d && d.line == t.line ? n : null)), d && d.line == t.line && (c = T(d, i)) && (l < 0 ? c < 0 : c > 0))
            return it(e, d, t, l, r);
        }
        let h = a.find(l < 0 ? -1 : 1);
        return (l < 0 ? u : f) && (h = Nr(e, h, l, h.line == t.line ? n : null)), h ? it(e, h, t, l, r) : null;
      }
    }
  return t;
}
function Ci(e, t, i, l, r) {
  let n = l || 1, s = it(e, t, i, n, r) || !r && it(e, t, i, n, !0) || it(e, t, i, -n, r) || !r && it(e, t, i, -n, !0);
  return s || (e.cantEdit = !0, x(e.first, 0));
}
function Nr(e, t, i, l) {
  return i < 0 && t.ch == 0 ? t.line > e.first ? k(e, x(t.line - 1)) : null : i > 0 && t.ch == (l || v(e, t.line)).text.length ? t.line < e.first + e.size - 1 ? x(t.line + 1, 0) : null : new x(t.line, t.ch + i);
}
function Jn(e) {
  e.setSelection(x(e.firstLine(), 0), x(e.lastLine()), ce);
}
function Vn(e, t, i) {
  let l = {
    canceled: !1,
    from: t.from,
    to: t.to,
    text: t.text,
    origin: t.origin,
    cancel: () => l.canceled = !0
  };
  return i && (l.update = (r, n, s, o) => {
    r && (l.from = k(e, r)), n && (l.to = k(e, n)), s && (l.text = s), o !== void 0 && (l.origin = o);
  }), E(e, "beforeChange", e, l), e.cm && E(e.cm, "beforeChange", e.cm, l), l.canceled ? (e.cm && (e.cm.curOp.updateInput = 2), null) : { from: l.from, to: l.to, text: l.text, origin: l.origin };
}
function ct(e, t, i) {
  if (e.cm) {
    if (!e.cm.curOp)
      return B(e.cm, ct)(e, t, i);
    if (e.cm.state.suppressEdits)
      return;
  }
  if ((se(e, "beforeChange") || e.cm && se(e.cm, "beforeChange")) && (t = Vn(e, t, !0), !t))
    return;
  let l = sn && !i && Qs(e, t.from, t.to);
  if (l)
    for (let r = l.length - 1; r >= 0; --r)
      Ar(e, { from: l[r].from, to: l[r].to, text: r ? [""] : t.text, origin: t.origin });
  else
    Ar(e, t);
}
function Ar(e, t) {
  if (t.text.length == 1 && t.text[0] == "" && T(t.from, t.to) == 0)
    return;
  let i = Yl(e, t);
  Yn(e, t, i, e.cm ? e.cm.curOp.id : NaN), qt(e, t, i, ll(e, t));
  let l = [];
  Me(e, (r, n) => {
    !n && K(l, r.history) == -1 && (es(r.history, t), l.push(r.history)), qt(r, t, null, ll(r, t));
  });
}
function oi(e, t, i) {
  let l = e.cm && e.cm.state.suppressEdits;
  if (l && !i)
    return;
  let r = e.history, n, s = e.sel, o = t == "undo" ? r.done : r.undone, a = t == "undo" ? r.undone : r.done, u = 0;
  for (; u < o.length && (n = o[u], !(i ? n.ranges && !n.equals(e.sel) : !n.ranges)); u++)
    ;
  if (u == o.length)
    return;
  for (r.lastOrigin = r.lastSelOrigin = null; ; )
    if (n = o.pop(), n.ranges) {
      if (vi(n, a), i && !n.equals(e.sel)) {
        U(e, n, { clearRedo: !1 });
        return;
      }
      s = n;
    } else if (l) {
      o.push(n);
      return;
    } else
      break;
  let f = [];
  vi(s, a), a.push({ changes: f, generation: r.generation }), r.generation = n.generation || ++r.maxGeneration;
  let h = se(e, "beforeChange") || e.cm && se(e.cm, "beforeChange");
  for (let d = n.changes.length - 1; d >= 0; --d) {
    let c = n.changes[d];
    if (c.origin = t, h && !Vn(e, c, !1)) {
      o.length = 0;
      return;
    }
    f.push(fl(e, c));
    let p = d ? Yl(e, c) : O(o);
    qt(e, c, p, kr(e, c)), !d && e.cm && e.cm.scrollIntoView({ from: c.from, to: We(c) });
    let m = [];
    Me(e, (g, b) => {
      !b && K(m, g.history) == -1 && (es(g.history, c), m.push(g.history)), qt(g, c, null, kr(g, c));
    });
  }
}
function Dr(e, t) {
  if (t != 0 && (e.first += t, e.sel = new ke(Di(e.sel.ranges, (i) => new H(
    x(i.anchor.line + t, i.anchor.ch),
    x(i.head.line + t, i.head.ch)
  )), e.sel.primIndex), e.cm)) {
    q(e.cm, e.first, e.first - t, t);
    for (let i = e.cm.display, l = i.viewFrom; l < i.viewTo; l++)
      Fe(e.cm, l, "gutter");
  }
}
function qt(e, t, i, l) {
  if (e.cm && !e.cm.curOp)
    return B(e.cm, qt)(e, t, i, l);
  if (t.to.line < e.first) {
    Dr(e, t.text.length - 1 - (t.to.line - t.from.line));
    return;
  }
  if (t.from.line > e.lastLine())
    return;
  if (t.from.line < e.first) {
    let n = t.text.length - 1 - (e.first - t.from.line);
    Dr(e, n), t = {
      from: x(e.first, 0),
      to: x(t.to.line + n, t.to.ch),
      text: [O(t.text)],
      origin: t.origin
    };
  }
  let r = e.lastLine();
  t.to.line > r && (t = {
    from: t.from,
    to: x(r, v(e, r).text.length),
    text: [t.text[0]],
    origin: t.origin
  }), t.removed = ze(e, t.from, t.to), i || (i = Yl(e, t)), e.cm ? ra(e.cm, t, l) : jl(e, t, l), Gi(e, i, ce), e.cantEdit && Ci(e, x(e.firstLine(), 0)) && (e.cantEdit = !1);
}
function ra(e, t, i) {
  let l = e.doc, r = e.display, n = t.from, s = t.to, o = !1, a = n.line;
  e.options.lineWrapping || (a = W(ge(v(l, n.line))), l.iter(a, s.line + 1, (d) => {
    if (d == r.maxLine)
      return o = !0, !0;
  })), l.sel.contains(t.from, t.to) > -1 && Qr(e), jl(l, t, i, An(e)), e.options.lineWrapping || (l.iter(a, n.line + t.text.length, (d) => {
    let c = bi(d);
    c > r.maxLineLength && (r.maxLine = d, r.maxLineLength = c, r.maxLineChanged = !0, o = !1);
  }), o && (e.curOp.updateMaxLine = !0)), _s(l, n.line), ei(e, 400);
  let u = t.text.length - (s.line - n.line) - 1;
  t.full ? q(e) : n.line == s.line && t.text.length == 1 && !Kn(e.doc, t) ? Fe(e, n.line, "text") : q(e, n.line, s.line + 1, u);
  let f = se(e, "changes"), h = se(e, "change");
  if (h || f) {
    let d = {
      from: n,
      to: s,
      text: t.text,
      removed: t.removed,
      origin: t.origin
    };
    h && z(e, "change", e, d), f && (e.curOp.changeObjs || (e.curOp.changeObjs = [])).push(d);
  }
  e.display.selForContextMenu = null;
}
function wt(e, t, i, l, r) {
  l || (l = i), T(l, i) < 0 && ([i, l] = [l, i]), typeof t == "string" && (t = e.splitLines(t)), ct(e, { from: i, to: l, text: t, origin: r });
}
function Or(e, t, i, l) {
  i < e.line ? e.line += l : t < e.line && (e.line = t, e.ch = 0);
}
function Wr(e, t, i, l) {
  for (let r = 0; r < e.length; ++r) {
    let n = e[r], s = !0;
    if (n.ranges) {
      n.copied || (n = e[r] = n.deepCopy(), n.copied = !0);
      for (let o = 0; o < n.ranges.length; o++)
        Or(n.ranges[o].anchor, t, i, l), Or(n.ranges[o].head, t, i, l);
      continue;
    }
    for (let o = 0; o < n.changes.length; ++o) {
      let a = n.changes[o];
      if (i < a.from.line)
        a.from = x(a.from.line + l, a.from.ch), a.to = x(a.to.line + l, a.to.ch);
      else if (t <= a.to.line) {
        s = !1;
        break;
      }
    }
    s || (e.splice(0, r + 1), r = 0);
  }
}
function es(e, t) {
  let i = t.from.line, l = t.to.line, r = t.text.length - (l - i) - 1;
  Wr(e.done, i, l, r), Wr(e.undone, i, l, r);
}
function Nt(e, t, i, l) {
  let r = t, n = t;
  return typeof t == "number" ? n = v(e, tn(e, t)) : r = W(t), r == null ? null : (l(n, r) && e.cm && Fe(e.cm, r, i), n);
}
function Ht(e) {
  this.lines = e, this.parent = null;
  let t = 0;
  for (let i = 0; i < e.length; ++i)
    e[i].parent = this, t += e[i].height;
  this.height = t;
}
Ht.prototype = {
  chunkSize() {
    return this.lines.length;
  },
  // Remove the n lines at offset 'at'.
  removeInner(e, t) {
    for (let i = e, l = e + t; i < l; ++i) {
      let r = this.lines[i];
      this.height -= r.height, io(r), z(r, "delete");
    }
    this.lines.splice(e, t);
  },
  // Helper used to collapse a small branch into a single leaf.
  collapse(e) {
    e.push.apply(e, this.lines);
  },
  // Insert the given array of lines at offset 'at', count them as
  // having the given height.
  insertInner(e, t, i) {
    this.height += i, this.lines = this.lines.slice(0, e).concat(t).concat(this.lines.slice(e));
    for (let l = 0; l < t.length; ++l)
      t[l].parent = this;
  },
  // Used to iterate over a part of the tree.
  iterN(e, t, i) {
    for (let l = e + t; e < l; ++e)
      if (i(this.lines[e]))
        return !0;
  }
};
function Ft(e) {
  this.children = e;
  let t = 0, i = 0;
  for (let l = 0; l < e.length; ++l) {
    let r = e[l];
    t += r.chunkSize(), i += r.height, r.parent = this;
  }
  this.size = t, this.height = i, this.parent = null;
}
Ft.prototype = {
  chunkSize() {
    return this.size;
  },
  removeInner(e, t) {
    this.size -= t;
    for (let i = 0; i < this.children.length; ++i) {
      let l = this.children[i], r = l.chunkSize();
      if (e < r) {
        let n = Math.min(t, r - e), s = l.height;
        if (l.removeInner(e, n), this.height -= s - l.height, r == n && (this.children.splice(i--, 1), l.parent = null), (t -= n) == 0)
          break;
        e = 0;
      } else
        e -= r;
    }
    if (this.size - t < 25 && (this.children.length > 1 || !(this.children[0] instanceof Ht))) {
      let i = [];
      this.collapse(i), this.children = [new Ht(i)], this.children[0].parent = this;
    }
  },
  collapse(e) {
    for (let t = 0; t < this.children.length; ++t)
      this.children[t].collapse(e);
  },
  insertInner(e, t, i) {
    this.size += t.length, this.height += i;
    for (let l = 0; l < this.children.length; ++l) {
      let r = this.children[l], n = r.chunkSize();
      if (e <= n) {
        if (r.insertInner(e, t, i), r.lines && r.lines.length > 50) {
          let s = r.lines.length % 25 + 25;
          for (let o = s; o < r.lines.length; ) {
            let a = new Ht(r.lines.slice(o, o += 25));
            r.height -= a.height, this.children.splice(++l, 0, a), a.parent = this;
          }
          r.lines = r.lines.slice(0, s), this.maybeSpill();
        }
        break;
      }
      e -= n;
    }
  },
  // When a node has grown, check whether it should be split.
  maybeSpill() {
    if (this.children.length <= 10)
      return;
    let e = this;
    do {
      let t = e.children.splice(e.children.length - 5, 5), i = new Ft(t);
      if (e.parent) {
        e.size -= i.size, e.height -= i.height;
        let l = K(e.parent.children, e);
        e.parent.children.splice(l + 1, 0, i);
      } else {
        let l = new Ft(e.children);
        l.parent = e, e.children = [l, i], e = l;
      }
      i.parent = e.parent;
    } while (e.children.length > 10);
    e.parent.maybeSpill();
  },
  iterN(e, t, i) {
    for (let l = 0; l < this.children.length; ++l) {
      let r = this.children[l], n = r.chunkSize();
      if (e < n) {
        let s = Math.min(t, n - e);
        if (r.iterN(e, s, i))
          return !0;
        if ((t -= s) == 0)
          break;
        e = 0;
      } else
        e -= n;
    }
  }
};
class Ql {
  constructor(t, i, l) {
    if (l)
      for (let r in l)
        l.hasOwnProperty(r) && (this[r] = l[r]);
    this.doc = t, this.node = i;
  }
  clear() {
    let t = this.doc.cm, i = this.line.widgets, l = this.line, r = W(l);
    if (r == null || !i)
      return;
    for (let s = 0; s < i.length; ++s)
      i[s] == this && i.splice(s--, 1);
    i.length || (l.widgets = null);
    let n = $t(this);
    pe(l, Math.max(0, l.height - n)), t && (J(t, () => {
      Hr(t, l, -n), Fe(t, r, "widget");
    }), z(t, "lineWidgetCleared", t, this, r));
  }
  changed() {
    let t = this.height, i = this.doc.cm, l = this.line;
    this.height = null;
    let r = $t(this) - t;
    r && (De(this.doc, l) || pe(l, l.height + r), i && J(i, () => {
      i.curOp.forceUpdate = !0, Hr(i, l, r), z(i, "lineWidgetChanged", i, this, W(l));
    }));
  }
}
gt(Ql);
function Hr(e, t, i) {
  Ce(t) < (e.curOp && e.curOp.scrollTop || e.doc.scrollTop) && Kl(e, i);
}
function na(e, t, i, l) {
  let r = new Ql(e, i, l), n = e.cm;
  return n && r.noHScroll && (n.display.alignWidgets = !0), Nt(e, t, "widget", (s) => {
    let o = s.widgets || (s.widgets = []);
    if (r.insertAt == null ? o.push(r) : o.splice(Math.min(o.length, Math.max(0, r.insertAt)), 0, r), r.line = s, n && !De(e, s)) {
      let a = Ce(s) < e.scrollTop;
      pe(s, s.height + $t(r)), a && Kl(n, r.height), n.curOp.forceUpdate = !0;
    }
    return !0;
  }), n && z(n, "lineWidgetAdded", n, r, typeof t == "number" ? t : W(t)), r;
}
let ts = 0;
class Jl {
  constructor(t, i) {
    this.lines = [], this.type = i, this.doc = t, this.id = ++ts;
  }
  // Clear the marker.
  clear() {
    if (this.explicitlyCleared)
      return;
    let t = this.doc.cm, i = t && !t.curOp;
    if (i && qe(t), se(this, "clear")) {
      let n = this.find();
      n && z(this, "clear", n.from, n.to);
    }
    let l = null, r = null;
    for (let n = 0; n < this.lines.length; ++n) {
      let s = this.lines[n], o = Kt(s.markedSpans, this);
      t && !this.collapsed ? Fe(t, W(s), "text") : t && (o.to != null && (r = W(s)), o.from != null && (l = W(s))), s.markedSpans = Ys(s.markedSpans, o), o.from == null && this.collapsed && !De(this.doc, s) && t && pe(s, ht(t.display));
    }
    if (t && this.collapsed && !t.options.lineWrapping)
      for (let n = 0; n < this.lines.length; ++n) {
        let s = ge(this.lines[n]), o = bi(s);
        o > t.display.maxLineLength && (t.display.maxLine = s, t.display.maxLineLength = o, t.display.maxLineChanged = !0);
      }
    l != null && t && this.collapsed && q(t, l, r + 1), this.lines.length = 0, this.explicitlyCleared = !0, this.atomic && this.doc.cantEdit && (this.doc.cantEdit = !1, t && Zn(t.doc)), t && z(t, "markerCleared", t, this, l, r), i && Ze(t), this.parent && this.parent.clear();
  }
  // Find the position of the marker in the document. Returns a {from,
  // to} object by default. Side can be passed to get a specific side
  // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
  // Pos objects returned contain a line object, rather than a line
  // number (used to prevent looking up the same line twice).
  find(t, i) {
    t == null && this.type == "bookmark" && (t = 1);
    let l, r;
    for (let n = 0; n < this.lines.length; ++n) {
      let s = this.lines[n], o = Kt(s.markedSpans, this);
      if (o.from != null && (l = x(i ? s : W(s), o.from), t == -1))
        return l;
      if (o.to != null && (r = x(i ? s : W(s), o.to), t == 1))
        return r;
    }
    return l && { from: l, to: r };
  }
  // Signals that the marker's widget changed, and surrounding layout
  // should be recomputed.
  changed() {
    let t = this.find(-1, !0), i = this, l = this.doc.cm;
    !t || !l || J(l, () => {
      let r = t.line, n = W(t.line), s = Hl(l, n);
      if (s && (Sn(s), l.curOp.selectionChanged = l.curOp.forceUpdate = !0), l.curOp.updateMaxLine = !0, !De(i.doc, r) && i.height != null) {
        let o = i.height;
        i.height = null;
        let a = $t(i) - o;
        a && pe(r, r.height + a);
      }
      z(l, "markerChanged", l, this);
    });
  }
  attachLine(t) {
    if (!this.lines.length && this.doc.cm) {
      let i = this.doc.cm.curOp;
      (!i.maybeHiddenMarkers || K(i.maybeHiddenMarkers, this) == -1) && (i.maybeUnhiddenMarkers || (i.maybeUnhiddenMarkers = [])).push(this);
    }
    this.lines.push(t);
  }
  detachLine(t) {
    if (this.lines.splice(K(this.lines, t), 1), !this.lines.length && this.doc.cm) {
      let i = this.doc.cm.curOp;
      (i.maybeHiddenMarkers || (i.maybeHiddenMarkers = [])).push(this);
    }
  }
}
gt(Jl);
function pt(e, t, i, l, r) {
  if (l && l.shared)
    return sa(e, t, i, l, r);
  if (e.cm && !e.cm.curOp)
    return B(e.cm, pt)(e, t, i, l, r);
  let n = new Jl(e, r), s = T(t, i);
  if (l && Ue(l, n, !1), s > 0 || s == 0 && n.clearWhenEmpty !== !1)
    return n;
  if (n.replacedWith && (n.collapsed = !0, n.widgetNode = rt("span", [n.replacedWith], "CodeMirror-widget"), l.handleMouseEvents || n.widgetNode.setAttribute("cm-ignore-events", "true"), l.insertLeft && (n.widgetNode.insertLeft = !0)), n.collapsed) {
    if (dr(e, t.line, t, i, n) || t.line != i.line && dr(e, i.line, t, i, n))
      throw new Error("Inserting collapsed marker partially overlapping an existing one");
    $s();
  }
  n.addToHistory && Yn(e, { from: t, to: i, origin: "markText" }, e.sel, NaN);
  let o = t.line, a = e.cm, u;
  if (e.iter(o, i.line + 1, (f) => {
    a && n.collapsed && !a.options.lineWrapping && ge(f) == a.display.maxLine && (u = !0), n.collapsed && o != t.line && pe(f, 0), js(f, new Fi(
      n,
      o == t.line ? t.ch : null,
      o == i.line ? i.ch : null
    ), e.cm && e.cm.curOp), ++o;
  }), n.collapsed && e.iter(t.line, i.line + 1, (f) => {
    De(e, f) && pe(f, 0);
  }), n.clearOnEnter && S(n, "beforeCursorEnter", () => n.clear()), n.readOnly && (Xs(), (e.history.done.length || e.history.undone.length) && e.clearHistory()), n.collapsed && (n.id = ++ts, n.atomic = !0), a) {
    if (u && (a.curOp.updateMaxLine = !0), n.collapsed)
      q(a, t.line, i.line + 1);
    else if (n.className || n.startStyle || n.endStyle || n.css || n.attributes || n.title)
      for (let f = t.line; f <= i.line; f++)
        Fe(a, f, "text");
    n.atomic && Zn(a.doc), z(a, "markerAdded", a, n);
  }
  return n;
}
class Vl {
  constructor(t, i) {
    this.markers = t, this.primary = i;
    for (let l = 0; l < t.length; ++l)
      t[l].parent = this;
  }
  clear() {
    if (!this.explicitlyCleared) {
      this.explicitlyCleared = !0;
      for (let t = 0; t < this.markers.length; ++t)
        this.markers[t].clear();
      z(this, "clear");
    }
  }
  find(t, i) {
    return this.primary.find(t, i);
  }
}
gt(Vl);
function sa(e, t, i, l, r) {
  l = Ue(l), l.shared = !1;
  let n = [pt(e, t, i, l, r)], s = n[0], o = l.widgetNode;
  return Me(e, (a) => {
    o && (l.widgetNode = o.cloneNode(!0)), n.push(pt(a, k(a, t), k(a, i), l, r));
    for (let u = 0; u < a.linked.length; ++u)
      if (a.linked[u].isParent)
        return;
    s = O(n);
  }), new Vl(n, s);
}
function Fr(e) {
  return e.findMarks(x(e.first, 0), e.clipPos(x(e.lastLine())), (t) => t.parent);
}
function oa(e, t) {
  for (let i = 0; i < t.length; i++) {
    let l = t[i], r = l.find(), n = e.clipPos(r.from), s = e.clipPos(r.to);
    if (T(n, s)) {
      let o = pt(e, n, s, l.primary, l.primary.type);
      l.markers.push(o), o.parent = l;
    }
  }
}
function aa(e) {
  for (let t = 0; t < e.length; t++) {
    let i = e[t], l = [i.primary.doc];
    Me(i.primary.doc, (r) => l.push(r));
    for (let r = 0; r < i.markers.length; r++) {
      let n = i.markers[r];
      K(l, n.doc) == -1 && (n.parent = null, i.markers.splice(r--, 1));
    }
  }
}
let ua = 0, Y = function(e, t, i, l, r) {
  if (!(this instanceof Y))
    return new Y(e, t, i, l, r);
  i == null && (i = 0), Ft.call(this, [new Ht([new _t("", null)])]), this.first = i, this.scrollTop = this.scrollLeft = 0, this.cantEdit = !1, this.cleanGeneration = 1, this.modeFrontier = this.highlightFrontier = i;
  let n = x(i, 0);
  this.sel = Oe(n), this.history = new hi(null), this.id = ++ua, this.modeOption = t, this.lineSep = l, this.direction = r == "rtl" ? "rtl" : "ltr", this.extend = !1, typeof e == "string" && (e = this.splitLines(e)), jl(this, { from: n, to: n, text: e }), U(this, Oe(n), ce);
};
Y.prototype = jr(Ft.prototype, {
  constructor: Y,
  // Iterate over the document. Supports two forms -- with only one
  // argument, it calls that for each line in the document. With
  // three, it iterates over the range given by the first two (with
  // the second being non-inclusive).
  iter: function(e, t, i) {
    i ? this.iterN(e - this.first, t - e, i) : this.iterN(this.first, this.first + this.size, e);
  },
  // Non-public interface for adding and removing lines.
  insert: function(e, t) {
    let i = 0;
    for (let l = 0; l < t.length; ++l)
      i += t[l].height;
    this.insertInner(e - this.first, t, i);
  },
  remove: function(e, t) {
    this.removeInner(e - this.first, t);
  },
  // From here, the methods are part of the public interface. Most
  // are also available from CodeMirror (editor) instances.
  getValue: function(e) {
    let t = qi(this, this.first, this.first + this.size);
    return e === !1 ? t : t.join(e || this.lineSeparator());
  },
  setValue: I(function(e) {
    let t = x(this.first, 0), i = this.first + this.size - 1;
    ct(this, {
      from: t,
      to: x(i, v(this, i).text.length),
      text: this.splitLines(e),
      origin: "setValue",
      full: !0
    }, !0), this.cm && Wt(this.cm, 0, 0), U(this, Oe(t), ce);
  }),
  replaceRange: function(e, t, i, l) {
    t = k(this, t), i = i ? k(this, i) : t, wt(this, e, t, i, l);
  },
  getRange: function(e, t, i) {
    let l = ze(this, k(this, e), k(this, t));
    return i === !1 ? l : i === "" ? l.join("") : l.join(i || this.lineSeparator());
  },
  /*修改codemirror代码*/
  newRange: function(e, t) {
    return new H(e, t);
  },
  getLine: function(e) {
    let t = this.getLineHandle(e);
    return t && t.text;
  },
  getLineHandle: function(e) {
    if (Ut(this, e))
      return v(this, e);
  },
  getLineNumber: function(e) {
    return W(e);
  },
  getLineHandleVisualStart: function(e) {
    return typeof e == "number" && (e = v(this, e)), ge(e);
  },
  lineCount: function() {
    return this.size;
  },
  firstLine: function() {
    return this.first;
  },
  lastLine: function() {
    return this.first + this.size - 1;
  },
  clipPos: function(e) {
    return k(this, e);
  },
  getCursor: function(e) {
    let t = this.sel.primary(), i;
    return e == null || e == "head" ? i = t.head : e == "anchor" ? i = t.anchor : e == "end" || e == "to" || e === !1 ? i = t.to() : i = t.from(), i;
  },
  listSelections: function() {
    return this.sel.ranges;
  },
  somethingSelected: function() {
    return this.sel.somethingSelected();
  },
  setCursor: I(function(e, t, i) {
    Mr(this, k(this, typeof e == "number" ? x(e, t || 0) : e), null, i);
  }),
  setSelection: I(function(e, t, i) {
    Mr(this, k(this, e), k(this, t || e), i);
  }),
  extendSelection: I(function(e, t, i) {
    zi(this, k(this, e), t && k(this, t), i);
  }),
  extendSelections: I(function(e, t) {
    Tr(this, sr(this, e), t);
  }),
  extendSelectionsBy: I(function(e, t) {
    let i = Di(this.sel.ranges, e);
    Tr(this, sr(this, i), t);
  }),
  setSelections: I(function(e, t, i) {
    if (!e.length)
      return;
    let l = [];
    for (let r = 0; r < e.length; r++)
      l[r] = new H(
        k(this, e[r].anchor),
        k(this, e[r].head || e[r].anchor)
      );
    t == null && (t = Math.min(e.length - 1, this.sel.primIndex)), U(this, ue(this.cm, l, t), i);
  }),
  addSelection: I(function(e, t, i) {
    let l = this.sel.ranges.slice(0);
    l.push(new H(k(this, e), k(this, t || e))), U(this, ue(this.cm, l, l.length - 1), i);
  }),
  getSelection: function(e) {
    let t = this.sel.ranges, i;
    for (let l = 0; l < t.length; l++) {
      let r = ze(this, t[l].from(), t[l].to());
      i = i ? i.concat(r) : r;
    }
    return e === !1 ? i : i.join(e || this.lineSeparator());
  },
  getSelections: function(e) {
    let t = [], i = this.sel.ranges;
    for (let l = 0; l < i.length; l++) {
      let r = ze(this, i[l].from(), i[l].to());
      e !== !1 && (r = r.join(e || this.lineSeparator())), t[l] = r;
    }
    return t;
  },
  replaceSelection: function(e, t, i) {
    let l = [];
    for (let r = 0; r < this.sel.ranges.length; r++)
      l[r] = e;
    this.replaceSelections(l, t, i || "+input");
  },
  replaceSelections: I(function(e, t, i) {
    let l = [], r = this.sel;
    for (let s = 0; s < r.ranges.length; s++) {
      let o = r.ranges[s];
      l[s] = { from: o.from(), to: o.to(), text: this.splitLines(e[s]), origin: i };
    }
    let n = t && t != "end" && Zo(this, l, t);
    for (let s = l.length - 1; s >= 0; s--)
      ct(this, l[s]);
    n ? jn(this, n) : this.cm && xt(this.cm);
  }),
  undo: I(function() {
    oi(this, "undo");
  }),
  redo: I(function() {
    oi(this, "redo");
  }),
  undoSelection: I(function() {
    oi(this, "undo", !0);
  }),
  redoSelection: I(function() {
    oi(this, "redo", !0);
  }),
  setExtending: function(e) {
    this.extend = e;
  },
  getExtending: function() {
    return this.extend;
  },
  historySize: function() {
    let e = this.history, t = 0, i = 0;
    for (let l = 0; l < e.done.length; l++)
      e.done[l].ranges || ++t;
    for (let l = 0; l < e.undone.length; l++)
      e.undone[l].ranges || ++i;
    return { undo: t, redo: i };
  },
  clearHistory: function() {
    this.history = new hi(this.history), Me(this, (e) => e.history = this.history, !0);
  },
  markClean: function() {
    this.cleanGeneration = this.changeGeneration(!0);
  },
  changeGeneration: function(e) {
    return e && (this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null), this.history.generation;
  },
  isClean: function(e) {
    return this.history.generation == (e || this.cleanGeneration);
  },
  getHistory: function() {
    return {
      done: Je(this.history.done),
      undone: Je(this.history.undone)
    };
  },
  setHistory: function(e) {
    let t = this.history = new hi(this.history);
    t.done = Je(e.done.slice(0), null, !0), t.undone = Je(e.undone.slice(0), null, !0);
  },
  setGutterMarker: I(function(e, t, i) {
    return Nt(this, e, "gutter", (l) => {
      let r = l.gutterMarkers || (l.gutterMarkers = {});
      return r[t] = i, !i && nr(r) && (l.gutterMarkers = null), !0;
    });
  }),
  clearGutter: I(function(e) {
    this.iter((t) => {
      t.gutterMarkers && t.gutterMarkers[e] && Nt(this, t, "gutter", () => (t.gutterMarkers[e] = null, nr(t.gutterMarkers) && (t.gutterMarkers = null), !0));
    });
  }),
  lineInfo: function(e) {
    let t;
    if (typeof e == "number") {
      if (!Ut(this, e) || (t = e, e = v(this, e), !e))
        return null;
    } else if (t = W(e), t == null)
      return null;
    return {
      line: t,
      handle: e,
      text: e.text,
      gutterMarkers: e.gutterMarkers,
      textClass: e.textClass,
      bgClass: e.bgClass,
      wrapClass: e.wrapClass,
      widgets: e.widgets
    };
  },
  addLineClass: I(function(e, t, i) {
    return Nt(this, e, t == "gutter" ? "gutter" : "class", (l) => {
      let r = t == "text" ? "textClass" : t == "background" ? "bgClass" : t == "gutter" ? "gutterClass" : "wrapClass";
      if (!l[r])
        l[r] = i;
      else {
        if (ut(i).test(l[r]))
          return !1;
        l[r] += " " + i;
      }
      return !0;
    });
  }),
  removeLineClass: I(function(e, t, i) {
    return Nt(this, e, t == "gutter" ? "gutter" : "class", (l) => {
      let r = t == "text" ? "textClass" : t == "background" ? "bgClass" : t == "gutter" ? "gutterClass" : "wrapClass", n = l[r];
      if (n)
        if (i == null)
          l[r] = null;
        else {
          let s = n.match(ut(i));
          if (!s)
            return !1;
          let o = s.index + s[0].length;
          l[r] = n.slice(0, s.index) + (!s.index || o == n.length ? "" : " ") + n.slice(o) || null;
        }
      else
        return !1;
      return !0;
    });
  }),
  addLineWidget: I(function(e, t, i) {
    return na(this, e, t, i);
  }),
  removeLineWidget: function(e) {
    e.clear();
  },
  markText: function(e, t, i) {
    return pt(this, k(this, e), k(this, t), i, i && i.type || "range");
  },
  setBookmark: function(e, t) {
    let i = {
      replacedWith: t && (t.nodeType == null ? t.widget : t),
      insertLeft: t && t.insertLeft,
      clearWhenEmpty: !1,
      shared: t && t.shared,
      handleMouseEvents: t && t.handleMouseEvents
    };
    return e = k(this, e), pt(this, e, e, i, "bookmark");
  },
  findMarksAt: function(e) {
    e = k(this, e);
    let t = [], i = v(this, e.line).markedSpans;
    if (i)
      for (let l = 0; l < i.length; ++l) {
        let r = i[l];
        (r.from == null || r.from <= e.ch) && (r.to == null || r.to >= e.ch) && t.push(r.marker.parent || r.marker);
      }
    return t;
  },
  findMarks: function(e, t, i) {
    e = k(this, e), t = k(this, t);
    let l = [], r = e.line;
    return this.iter(e.line, t.line + 1, (n) => {
      let s = n.markedSpans;
      if (s)
        for (let o = 0; o < s.length; o++) {
          let a = s[o];
          !(a.to != null && r == e.line && e.ch >= a.to || a.from == null && r != e.line || a.from != null && r == t.line && a.from >= t.ch) && (!i || i(a.marker)) && l.push(a.marker.parent || a.marker);
        }
      ++r;
    }), l;
  },
  getAllMarks: function() {
    let e = [];
    return this.iter((t) => {
      let i = t.markedSpans;
      if (i)
        for (let l = 0; l < i.length; ++l)
          i[l].from != null && e.push(i[l].marker);
    }), e;
  },
  posFromIndex: function(e) {
    let t, i = this.first, l = this.lineSeparator().length;
    return this.iter((r) => {
      let n = r.text.length + l;
      if (n > e)
        return t = e, !0;
      e -= n, ++i;
    }), k(this, x(i, t));
  },
  indexFromPos: function(e) {
    e = k(this, e);
    let t = e.ch;
    if (e.line < this.first || e.ch < 0)
      return 0;
    let i = this.lineSeparator().length;
    return this.iter(this.first, e.line, (l) => {
      t += l.text.length + i;
    }), t;
  },
  copy: function(e) {
    let t = new Y(
      qi(this, this.first, this.first + this.size),
      this.modeOption,
      this.first,
      this.lineSep,
      this.direction
    );
    return t.scrollTop = this.scrollTop, t.scrollLeft = this.scrollLeft, t.sel = this.sel, t.extend = !1, e && (t.history.undoDepth = this.history.undoDepth, t.setHistory(this.getHistory())), t;
  },
  linkedDoc: function(e) {
    e || (e = {});
    let t = this.first, i = this.first + this.size;
    e.from != null && e.from > t && (t = e.from), e.to != null && e.to < i && (i = e.to);
    let l = new Y(qi(this, t, i), e.mode || this.modeOption, t, this.lineSep, this.direction);
    return e.sharedHist && (l.history = this.history), (this.linked || (this.linked = [])).push({ doc: l, sharedHist: e.sharedHist }), l.linked = [{ doc: this, isParent: !0, sharedHist: e.sharedHist }], oa(l, Fr(this)), l;
  },
  unlinkDoc: function(e) {
    if (e instanceof P && (e = e.doc), this.linked) {
      for (let t = 0; t < this.linked.length; ++t)
        if (this.linked[t].doc == e) {
          this.linked.splice(t, 1), e.unlinkDoc(this), aa(Fr(this));
          break;
        }
    }
    if (e.history == this.history) {
      let t = [e.id];
      Me(e, (i) => t.push(i.id), !0), e.history = new hi(null), e.history.done = Je(this.history.done, t), e.history.undone = Je(this.history.undone, t);
    }
  },
  iterLinkedDocs: function(e) {
    Me(this, e);
  },
  getMode: function() {
    return this.mode;
  },
  getEditor: function() {
    return this.cm;
  },
  splitLines: function(e) {
    return this.lineSep ? e.split(this.lineSep) : wl(e);
  },
  lineSeparator: function() {
    return this.lineSep || `
`;
  },
  setDirection: I(function(e) {
    e != "rtl" && (e = "ltr"), e != this.direction && (this.direction = e, this.iter((t) => t.order = null), this.cm && Qo(this.cm));
  })
});
Y.prototype.eachLine = Y.prototype.iter;
let is = 0;
function fa(e) {
  let t = this;
  if (ls(t), R(t, e) || Se(t.display, e))
    return;
  j(e), N && (is = +/* @__PURE__ */ new Date());
  let i = Ke(t, e, !0), l = e.dataTransfer.files;
  if (!(!i || t.isReadOnly()))
    if (l && l.length && window.FileReader && window.File) {
      let r = l.length, n = Array(r), s = 0;
      const o = () => {
        ++s == r && B(t, () => {
          i = k(t.doc, i);
          let u = {
            from: i,
            to: i,
            text: t.doc.splitLines(
              n.filter((f) => f != null).join(t.doc.lineSeparator())
            ),
            origin: "paste"
          };
          ct(t.doc, u), jn(t.doc, Oe(k(t.doc, i), k(t.doc, We(u))));
        })();
      }, a = (u, f) => {
        if (t.options.allowDropFileTypes && K(t.options.allowDropFileTypes, u.type) == -1) {
          o();
          return;
        }
        let h = new FileReader();
        h.onerror = () => o(), h.onload = () => {
          let d = h.result;
          if (/[\x00-\x08\x0e-\x1f]{2}/.test(d)) {
            o();
            return;
          }
          n[f] = d, o();
        }, h.readAsText(u);
      };
      for (let u = 0; u < l.length; u++)
        a(l[u], u);
    } else {
      if (t.state.draggingText && t.doc.sel.contains(i) > -1) {
        t.state.draggingText(e), setTimeout(() => t.display.input.focus(), 20);
        return;
      }
      try {
        let r = e.dataTransfer.getData("Text");
        if (r) {
          let n;
          if (t.state.draggingText && !t.state.draggingText.copy && (n = t.listSelections()), Gi(t.doc, Oe(i, i)), n)
            for (let s = 0; s < n.length; ++s)
              wt(t.doc, "", n[s].anchor, n[s].head, "drag");
          t.replaceSelection(r, "around", "paste"), t.display.input.focus();
        }
      } catch {
      }
    }
}
function ha(e, t) {
  if (N && (!e.state.draggingText || +/* @__PURE__ */ new Date() - is < 100)) {
    Gt(t);
    return;
  }
  if (!(R(e, t) || Se(e.display, t)) && (t.dataTransfer.setData("Text", e.getSelection()), t.dataTransfer.effectAllowed = "copyMove", t.dataTransfer.setDragImage && !Mi)) {
    let i = C("img", null, null, "position: fixed; left: 0; top: 0;");
    i.src = "", fe && (i.width = i.height = 1, e.display.wrapper.appendChild(i), i._top = i.offsetTop), t.dataTransfer.setDragImage(i, 0, 0), fe && i.parentNode.removeChild(i);
  }
}
function da(e, t) {
  let i = Ke(e, t);
  if (!i)
    return;
  let l = document.createDocumentFragment();
  On(e, i, l), e.display.dragCursor || (e.display.dragCursor = C("div", null, "CodeMirror-cursors CodeMirror-dragcursors"), e.display.lineSpace.insertBefore(e.display.dragCursor, e.display.cursorDiv)), ie(e.display.dragCursor, l);
}
function ls(e) {
  e.display.dragCursor && (e.display.lineSpace.removeChild(e.display.dragCursor), e.display.dragCursor = null);
}
function Pr(e) {
  if (!document.getElementsByClassName)
    return;
  let t = document.getElementsByClassName("CodeMirror"), i = [];
  for (let l = 0; l < t.length; l++) {
    let r = t[l].CodeMirror;
    r && i.push(r);
  }
  i.length && i[0].operation(() => {
    for (let l = 0; l < i.length; l++)
      e(i[l]);
  });
}
let Er = !1;
function ca() {
  Er || (pa(), Er = !0);
}
function pa() {
  let e;
  S(window, "resize", () => {
    e == null && (e = setTimeout(() => {
      e = null, Pr(ga);
    }, 100));
  }), S(window, "blur", () => Pr(bt));
}
function ga(e) {
  let t = e.display;
  t.cachedCharWidth = t.cachedTextHeight = t.cachedPaddingH = null, t.scrollbarsClipped = !1, e.setSize();
}
let He = {
  3: "Pause",
  8: "Backspace",
  9: "Tab",
  13: "Enter",
  16: "Shift",
  17: "Ctrl",
  18: "Alt",
  19: "Pause",
  20: "CapsLock",
  27: "Esc",
  32: "Space",
  33: "PageUp",
  34: "PageDown",
  35: "End",
  36: "Home",
  37: "Left",
  38: "Up",
  39: "Right",
  40: "Down",
  44: "PrintScrn",
  45: "Insert",
  46: "Delete",
  59: ";",
  61: "=",
  91: "Mod",
  92: "Mod",
  93: "Mod",
  106: "*",
  107: "=",
  109: "-",
  110: ".",
  111: "/",
  145: "ScrollLock",
  173: "-",
  186: ";",
  187: "=",
  188: ",",
  189: "-",
  190: ".",
  191: "/",
  192: "`",
  219: "[",
  220: "\\",
  221: "]",
  222: "'",
  224: "Mod",
  63232: "Up",
  63233: "Down",
  63234: "Left",
  63235: "Right",
  63272: "Delete",
  63273: "Home",
  63275: "End",
  63276: "PageUp",
  63277: "PageDown",
  63302: "Insert"
};
for (let e = 0; e < 10; e++)
  He[e + 48] = He[e + 96] = String(e);
for (let e = 65; e <= 90; e++)
  He[e] = String.fromCharCode(e);
for (let e = 1; e <= 12; e++)
  He[e + 111] = He[e + 63235] = "F" + e;
let xe = {};
xe.basic = {
  Left: "goCharLeft",
  Right: "goCharRight",
  Up: "goLineUp",
  Down: "goLineDown",
  End: "goLineEnd",
  Home: "goLineStartSmart",
  PageUp: "goPageUp",
  PageDown: "goPageDown",
  Delete: "delCharAfter",
  Backspace: "delCharBefore",
  "Shift-Backspace": "delCharBefore",
  Tab: "defaultTab",
  "Shift-Tab": "indentAuto",
  Enter: "newlineAndIndent",
  Insert: "toggleOverwrite",
  Esc: "singleSelection"
};
xe.pcDefault = {
  "Ctrl-A": "selectAll",
  "Ctrl-D": "deleteLine",
  "Ctrl-Z": "undo",
  "Shift-Ctrl-Z": "redo",
  "Ctrl-Y": "redo",
  "Ctrl-Home": "goDocStart",
  "Ctrl-End": "goDocEnd",
  "Ctrl-Up": "goLineUp",
  "Ctrl-Down": "goLineDown",
  "Ctrl-Left": "goGroupLeft",
  "Ctrl-Right": "goGroupRight",
  "Alt-Left": "goLineStart",
  "Alt-Right": "goLineEnd",
  "Ctrl-Backspace": "delGroupBefore",
  "Ctrl-Delete": "delGroupAfter",
  "Ctrl-S": "save",
  "Ctrl-F": "find",
  "Ctrl-G": "findNext",
  "Shift-Ctrl-G": "findPrev",
  "Shift-Ctrl-F": "replace",
  "Shift-Ctrl-R": "replaceAll",
  "Ctrl-[": "indentLess",
  "Ctrl-]": "indentMore",
  "Ctrl-U": "undoSelection",
  "Shift-Ctrl-U": "redoSelection",
  "Alt-U": "redoSelection",
  fallthrough: "basic"
};
xe.emacsy = {
  "Ctrl-F": "goCharRight",
  "Ctrl-B": "goCharLeft",
  "Ctrl-P": "goLineUp",
  "Ctrl-N": "goLineDown",
  "Ctrl-A": "goLineStart",
  "Ctrl-E": "goLineEnd",
  "Ctrl-V": "goPageDown",
  "Shift-Ctrl-V": "goPageUp",
  "Ctrl-D": "delCharAfter",
  "Ctrl-H": "delCharBefore",
  "Alt-Backspace": "delWordBefore",
  "Ctrl-K": "killLine",
  "Ctrl-T": "transposeChars",
  "Ctrl-O": "openLine"
};
xe.macDefault = {
  "Cmd-A": "selectAll",
  "Cmd-D": "deleteLine",
  "Cmd-Z": "undo",
  "Shift-Cmd-Z": "redo",
  "Cmd-Y": "redo",
  "Cmd-Home": "goDocStart",
  "Cmd-Up": "goDocStart",
  "Cmd-End": "goDocEnd",
  "Cmd-Down": "goDocEnd",
  "Alt-Left": "goGroupLeft",
  "Alt-Right": "goGroupRight",
  "Cmd-Left": "goLineLeft",
  "Cmd-Right": "goLineRight",
  "Alt-Backspace": "delGroupBefore",
  "Ctrl-Alt-Backspace": "delGroupAfter",
  "Alt-Delete": "delGroupAfter",
  "Cmd-S": "save",
  "Cmd-F": "find",
  "Cmd-G": "findNext",
  "Shift-Cmd-G": "findPrev",
  "Cmd-Alt-F": "replace",
  "Shift-Cmd-Alt-F": "replaceAll",
  "Cmd-[": "indentLess",
  "Cmd-]": "indentMore",
  "Cmd-Backspace": "delWrappedLineLeft",
  "Cmd-Delete": "delWrappedLineRight",
  "Cmd-U": "undoSelection",
  "Shift-Cmd-U": "redoSelection",
  "Ctrl-Up": "goDocStart",
  "Ctrl-Down": "goDocEnd",
  fallthrough: ["basic", "emacsy"]
};
xe.default = ne ? xe.macDefault : xe.pcDefault;
function ya(e) {
  let t = e.split(/-(?!$)/);
  e = t[t.length - 1];
  let i, l, r, n;
  for (let s = 0; s < t.length - 1; s++) {
    let o = t[s];
    if (/^(cmd|meta|m)$/i.test(o))
      n = !0;
    else if (/^a(lt)?$/i.test(o))
      i = !0;
    else if (/^(c|ctrl|control)$/i.test(o))
      l = !0;
    else if (/^s(hift)?$/i.test(o))
      r = !0;
    else
      throw new Error("Unrecognized modifier name: " + o);
  }
  return i && (e = "Alt-" + e), l && (e = "Ctrl-" + e), n && (e = "Cmd-" + e), r && (e = "Shift-" + e), e;
}
function ma(e) {
  let t = {};
  for (let i in e)
    if (e.hasOwnProperty(i)) {
      let l = e[i];
      if (/^(name|fallthrough|(de|at)tach)$/.test(i))
        continue;
      if (l == "...") {
        delete e[i];
        continue;
      }
      let r = Di(i.split(" "), ya);
      for (let n = 0; n < r.length; n++) {
        let s, o;
        n == r.length - 1 ? (o = r.join(" "), s = l) : (o = r.slice(0, n + 1).join(" "), s = "...");
        let a = t[o];
        if (!a)
          t[o] = s;
        else if (a != s)
          throw new Error("Inconsistent bindings for " + o);
      }
      delete e[i];
    }
  for (let i in t)
    e[i] = t[i];
  return e;
}
function at(e, t, i, l) {
  t = Si(t);
  let r = t.call ? t.call(e, l) : t[e];
  if (r === !1)
    return "nothing";
  if (r === "...")
    return "multi";
  if (r != null && i(r))
    return "handled";
  if (t.fallthrough) {
    if (Object.prototype.toString.call(t.fallthrough) != "[object Array]")
      return at(e, t.fallthrough, i, l);
    for (let n = 0; n < t.fallthrough.length; n++) {
      let s = at(e, t.fallthrough[n], i, l);
      if (s)
        return s;
    }
  }
}
function rs(e) {
  let t = typeof e == "string" ? e : He[e.keyCode];
  return t == "Ctrl" || t == "Alt" || t == "Shift" || t == "Mod";
}
function ns(e, t, i) {
  let l = e;
  return t.altKey && l != "Alt" && (e = "Alt-" + e), (lr ? t.metaKey : t.ctrlKey) && l != "Ctrl" && (e = "Ctrl-" + e), (lr ? t.ctrlKey : t.metaKey) && l != "Mod" && (e = "Cmd-" + e), !i && t.shiftKey && l != "Shift" && (e = "Shift-" + e), e;
}
function ss(e, t) {
  if (fe && e.keyCode == 34 && e.char)
    return !1;
  let i = He[e.keyCode];
  return i == null || e.altGraphKey ? !1 : (e.keyCode == 3 && e.code && (i = e.code), ns(i, e, t));
}
function Si(e) {
  return typeof e == "string" ? xe[e] : e;
}
function Ve(e, t) {
  let i = e.doc.sel.ranges, l = [];
  for (let r = 0; r < i.length; r++) {
    let n = t(i[r]);
    for (; l.length && T(n.from, O(l).to) <= 0; ) {
      let s = l.pop();
      if (T(s.from, n.from) < 0) {
        n.from = s.from;
        break;
      }
    }
    l.push(n);
  }
  J(e, () => {
    for (let r = l.length - 1; r >= 0; r--)
      wt(e.doc, "", l[r].from, l[r].to, "+delete");
    xt(e);
  });
}
function er(e, t, i) {
  let l = qr(e.text, t + i, i);
  return l < 0 || l > e.text.length ? null : l;
}
function hl(e, t, i) {
  let l = er(e, t.ch, i);
  return l == null ? null : new x(t.line, l, i < 0 ? "after" : "before");
}
function tr(e, t, i, l, r) {
  if (e) {
    t.doc.direction == "rtl" && (r = -r);
    let n = Le(i, t.doc.direction);
    if (n) {
      let s = r < 0 ? O(n) : n[0], a = r < 0 == (s.level == 1) ? "after" : "before", u;
      if (s.level > 0 || t.doc.direction == "rtl") {
        let f = yt(t, i);
        u = r < 0 ? i.text.length - 1 : 0;
        let h = me(t, f, u).top;
        u = Bt((d) => me(t, f, d).top == h, r < 0 == (s.level == 1) ? s.from : s.to - 1, u), a == "before" && (u = er(i, u, 1));
      } else
        u = r < 0 ? s.to : s.from;
      return new x(l, u, a);
    }
  }
  return new x(l, r < 0 ? i.text.length : 0, r < 0 ? "before" : "after");
}
function ba(e, t, i, l) {
  let r = Le(t, e.doc.direction);
  if (!r)
    return hl(t, i, l);
  i.ch >= t.text.length ? (i.ch = t.text.length, i.sticky = "before") : i.ch <= 0 && (i.ch = 0, i.sticky = "after");
  let n = zt(r, i.ch, i.sticky), s = r[n];
  if (e.doc.direction == "ltr" && s.level % 2 == 0 && (l > 0 ? s.to > i.ch : s.from < i.ch))
    return hl(t, i, l);
  let o = (p, m) => er(t, p instanceof x ? p.ch : p, m), a, u = (p) => e.options.lineWrapping ? (a = a || yt(e, t), Nn(e, t, a, p)) : { begin: 0, end: t.text.length }, f = u(i.sticky == "before" ? o(i, -1) : i.ch);
  if (e.doc.direction == "rtl" || s.level == 1) {
    let p = s.level == 1 == l < 0, m = o(i, p ? 1 : -1);
    if (m != null && (p ? m <= s.to && m <= f.end : m >= s.from && m >= f.begin)) {
      let g = p ? "before" : "after";
      return new x(i.line, m, g);
    }
  }
  let h = (p, m, g) => {
    let b = (y, L) => L ? new x(i.line, o(y, 1), "before") : new x(i.line, y, "after");
    for (; p >= 0 && p < r.length; p += m) {
      let y = r[p], L = m > 0 == (y.level != 1), w = L ? g.begin : o(g.end, -1);
      if (y.from <= w && w < y.to || (w = L ? y.from : o(y.to, -1), g.begin <= w && w < g.end))
        return b(w, L);
    }
  }, d = h(n + l, l, f);
  if (d)
    return d;
  let c = l > 0 ? f.end : o(f.begin, -1);
  return c != null && !(l > 0 && c == t.text.length) && (d = h(l > 0 ? 0 : r.length - 1, l, u(c)), d) ? d : null;
}
let Zt = {
  selectAll: Jn,
  singleSelection: (e) => e.setSelection(e.getCursor("anchor"), e.getCursor("head"), ce),
  killLine: (e) => Ve(e, (t) => {
    if (t.empty()) {
      let i = v(e.doc, t.head.line).text.length;
      return t.head.ch == i && t.head.line < e.lastLine() ? { from: t.head, to: x(t.head.line + 1, 0) } : { from: t.head, to: x(t.head.line, i) };
    } else
      return { from: t.from(), to: t.to() };
  }),
  deleteLine: (e) => Ve(e, (t) => ({
    from: x(t.from().line, 0),
    to: k(e.doc, x(t.to().line + 1, 0))
  })),
  delLineLeft: (e) => Ve(e, (t) => ({
    from: x(t.from().line, 0),
    to: t.from()
  })),
  delWrappedLineLeft: (e) => Ve(e, (t) => {
    let i = e.charCoords(t.head, "div").top + 5;
    return { from: e.coordsChar({ left: 0, top: i }, "div"), to: t.from() };
  }),
  delWrappedLineRight: (e) => Ve(e, (t) => {
    let i = e.charCoords(t.head, "div").top + 5, l = e.coordsChar({ left: e.display.lineDiv.offsetWidth + 100, top: i }, "div");
    return { from: t.from(), to: l };
  }),
  undo: (e) => e.undo(),
  redo: (e) => e.redo(),
  undoSelection: (e) => e.undoSelection(),
  redoSelection: (e) => e.redoSelection(),
  goDocStart: (e) => e.extendSelection(x(e.firstLine(), 0)),
  goDocEnd: (e) => e.extendSelection(x(e.lastLine())),
  goLineStart: (e) => e.extendSelectionsBy(
    (t) => os(e, t.head.line),
    { origin: "+move", bias: 1 }
  ),
  goLineStartSmart: (e) => e.extendSelectionsBy(
    (t) => Ir(e, t.head),
    { origin: "+move", bias: 1 }
  ),
  goLineEnd: (e) => e.extendSelectionsBy(
    (t) => xa(e, t.head.line),
    { origin: "+move", bias: -1 }
  ),
  goLineRight: (e) => e.extendSelectionsBy((t) => {
    let i = e.cursorCoords(t.head, "div").top + 5;
    return e.coordsChar({ left: e.display.lineDiv.offsetWidth + 100, top: i }, "div");
  }, At),
  goLineLeft: (e) => e.extendSelectionsBy((t) => {
    let i = e.cursorCoords(t.head, "div").top + 5;
    return e.coordsChar({ left: 0, top: i }, "div");
  }, At),
  goLineLeftSmart: (e) => e.extendSelectionsBy((t) => {
    let i = e.cursorCoords(t.head, "div").top + 5, l = e.coordsChar({ left: 0, top: i }, "div");
    return l.ch < e.getLine(l.line).search(/\S/) ? Ir(e, t.head) : l;
  }, At),
  goLineUp: (e) => e.moveV(-1, "line"),
  goLineDown: (e) => e.moveV(1, "line"),
  goPageUp: (e) => e.moveV(-1, "page"),
  goPageDown: (e) => e.moveV(1, "page"),
  goCharLeft: (e) => e.moveH(-1, "char"),
  goCharRight: (e) => e.moveH(1, "char"),
  goColumnLeft: (e) => e.moveH(-1, "column"),
  goColumnRight: (e) => e.moveH(1, "column"),
  goWordLeft: (e) => e.moveH(-1, "word"),
  goGroupRight: (e) => e.moveH(1, "group"),
  goGroupLeft: (e) => e.moveH(-1, "group"),
  goWordRight: (e) => e.moveH(1, "word"),
  delCharBefore: (e) => e.deleteH(-1, "codepoint"),
  delCharAfter: (e) => e.deleteH(1, "char"),
  delWordBefore: (e) => e.deleteH(-1, "word"),
  delWordAfter: (e) => e.deleteH(1, "word"),
  delGroupBefore: (e) => e.deleteH(-1, "group"),
  delGroupAfter: (e) => e.deleteH(1, "group"),
  indentAuto: (e) => e.indentSelection("smart"),
  indentMore: (e) => e.indentSelection("add"),
  indentLess: (e) => e.indentSelection("subtract"),
  insertTab: (e) => e.replaceSelection("	"),
  insertSoftTab: (e) => {
    let t = [], i = e.listSelections(), l = e.options.tabSize;
    for (let r = 0; r < i.length; r++) {
      let n = i[r].from(), s = le(e.getLine(n.line), n.ch, l);
      t.push(ml(l - s % l));
    }
    e.replaceSelections(t);
  },
  defaultTab: (e) => {
    e.somethingSelected() ? e.indentSelection("add") : e.execCommand("insertTab");
  },
  // Swap the two chars left and right of each selection's head.
  // Move cursor behind the two swapped characters afterwards.
  //
  // Doesn't consider line feeds a character.
  // Doesn't scan more than one line above to find a character.
  // Doesn't do anything on an empty line.
  // Doesn't do anything with non-empty selections.
  transposeChars: (e) => J(e, () => {
    let t = e.listSelections(), i = [];
    for (let l = 0; l < t.length; l++) {
      if (!t[l].empty())
        continue;
      let r = t[l].head, n = v(e.doc, r.line).text;
      if (n) {
        if (r.ch == n.length && (r = new x(r.line, r.ch - 1)), r.ch > 0)
          r = new x(r.line, r.ch + 1), e.replaceRange(
            n.charAt(r.ch - 1) + n.charAt(r.ch - 2),
            x(r.line, r.ch - 2),
            r,
            "+transpose"
          );
        else if (r.line > e.doc.first) {
          let s = v(e.doc, r.line - 1).text;
          s && (r = new x(r.line, 1), e.replaceRange(
            n.charAt(0) + e.doc.lineSeparator() + s.charAt(s.length - 1),
            x(r.line - 1, s.length - 1),
            r,
            "+transpose"
          ));
        }
      }
      i.push(new H(r, r));
    }
    e.setSelections(i);
  }),
  newlineAndIndent: (e) => J(e, () => {
    let t = e.listSelections();
    for (let i = t.length - 1; i >= 0; i--)
      e.replaceRange(e.doc.lineSeparator(), t[i].anchor, t[i].head, "+input");
    t = e.listSelections();
    for (let i = 0; i < t.length; i++)
      e.indentLine(t[i].from().line, null, !0);
    xt(e);
  }),
  openLine: (e) => e.replaceSelection(`
`, "start"),
  toggleOverwrite: (e) => e.toggleOverwrite()
};
function os(e, t) {
  let i = v(e.doc, t), l = ge(i);
  return l != i && (t = W(l)), tr(!0, e, l, t, 1);
}
function xa(e, t) {
  let i = v(e.doc, t), l = Vs(i);
  return l != i && (t = W(l)), tr(!0, e, i, t, -1);
}
function Ir(e, t) {
  let i = os(e, t.line), l = v(e.doc, i.line), r = Le(l, e.doc.direction);
  if (!r || r[0].level == 0) {
    let n = Math.max(i.ch, l.text.search(/\S/)), s = t.line == i.line && t.ch <= n && t.ch;
    return x(i.line, s ? 0 : n, i.sticky);
  }
  return i;
}
function di(e, t, i) {
  if (typeof t == "string" && (t = Zt[t], !t))
    return !1;
  e.display.input.ensurePolled();
  let l = e.display.shift, r = !1;
  try {
    e.isReadOnly() && (e.state.suppressEdits = !0), i && (e.display.shift = !1), r = t(e) != Ai;
  } finally {
    e.display.shift = l, e.state.suppressEdits = !1;
  }
  return r;
}
function wa(e, t, i) {
  for (let l = 0; l < e.state.keyMaps.length; l++) {
    let r = at(t, e.state.keyMaps[l], i, e);
    if (r)
      return r;
  }
  return e.options.extraKeys && at(t, e.options.extraKeys, i, e) || at(t, e.options.keyMap, i, e);
}
let va = new ft();
function Pt(e, t, i, l) {
  let r = e.state.keySeq;
  if (r) {
    if (rs(t))
      return "handled";
    if (/\'$/.test(t) ? e.state.keySeq = null : va.set(50, () => {
      e.state.keySeq == r && (e.state.keySeq = null, e.display.input.reset());
    }), Rr(e, r + " " + t, i, l))
      return !0;
  }
  return Rr(e, t, i, l);
}
function Rr(e, t, i, l) {
  let r = wa(e, t, l);
  return r == "multi" && (e.state.keySeq = t), r == "handled" && z(e, "keyHandled", e, t, i), (r == "handled" || r == "multi") && (j(i), Bl(e)), !!r;
}
function as(e, t) {
  let i = ss(t, !0);
  return i ? t.shiftKey && !e.state.keySeq ? Pt(e, "Shift-" + i, t, (l) => di(e, l, !0)) || Pt(e, i, t, (l) => {
    if (typeof l == "string" ? /^go[A-Z]/.test(l) : l.motion)
      return di(e, l);
  }) : Pt(e, i, t, (l) => di(e, l)) : !1;
}
function Ca(e, t, i) {
  return Pt(e, "'" + i + "'", t, (l) => di(e, l, !0));
}
let dl = null;
function us(e) {
  let t = this;
  if (e.target && e.target != t.display.input.getField() || (t.curOp.focus = re(), R(t, e)))
    return;
  N && F < 11 && e.keyCode == 27 && (e.returnValue = !1);
  let i = e.keyCode;
  t.display.shift = i == 16 || e.shiftKey;
  let l = as(t, e);
  fe && (dl = l ? i : null, !l && i == 88 && !Is && (ne ? e.metaKey : e.ctrlKey) && t.replaceSelection("", null, "cut")), we && !ne && !l && i == 46 && e.shiftKey && !e.ctrlKey && document.execCommand && document.execCommand("cut"), i == 18 && !/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className) && Sa(t);
}
function Sa(e) {
  let t = e.display.lineDiv;
  $e(t, "CodeMirror-crosshair");
  function i(l) {
    (l.keyCode == 18 || !l.altKey) && (Xe(t, "CodeMirror-crosshair"), te(document, "keyup", i), te(document, "mouseover", i));
  }
  S(document, "keyup", i), S(document, "mouseover", i);
}
function fs(e) {
  e.keyCode == 16 && (this.doc.sel.shift = !1), R(this, e);
}
function hs(e) {
  let t = this;
  if (e.target && e.target != t.display.input.getField() || Se(t.display, e) || R(t, e) || e.ctrlKey && !e.altKey || ne && e.metaKey)
    return;
  let i = e.keyCode, l = e.charCode;
  if (fe && i == dl) {
    dl = null, j(e);
    return;
  }
  if (fe && (!e.which || e.which < 10) && as(t, e))
    return;
  let r = String.fromCharCode(l == null ? i : l);
  r != "\b" && (Ca(t, e, r) || t.display.input.onKeyPress(e));
}
const La = 400;
class Br {
  constructor(t, i, l) {
    this.time = t, this.pos = i, this.button = l;
  }
  compare(t, i, l) {
    return this.time + La > t && T(i, this.pos) == 0 && l == this.button;
  }
}
let Lt, kt;
function ka(e, t) {
  let i = +/* @__PURE__ */ new Date();
  return kt && kt.compare(i, e, t) ? (Lt = kt = null, "triple") : Lt && Lt.compare(i, e, t) ? (kt = new Br(i, e, t), Lt = null, "double") : (Lt = new Br(i, e, t), kt = null, "single");
}
function ds(e) {
  let t = this, i = t.display;
  if (R(t, e) || i.activeTouch && i.input.supportsTouch())
    return;
  if (i.input.ensurePolled(), i.shift = e.shiftKey, Se(i, e)) {
    $ || (i.scroller.draggable = !1, setTimeout(() => i.scroller.draggable = !0, 100));
    return;
  }
  if (cl(t, e))
    return;
  let l = Ke(t, e), r = Vr(e), n = l ? ka(l, r) : "single";
  window.focus(), r == 1 && t.state.selectingText && t.state.selectingText(e), !(l && Ta(t, r, l, n, e)) && (r == 1 ? l ? Na(t, l, n, e) : xl(e) == i.scroller && j(e) : r == 2 ? (l && zi(t.doc, l), setTimeout(() => i.input.focus(), 20)) : r == 3 && (gl ? t.display.input.onContextMenu(e) : zl(t)));
}
function Ta(e, t, i, l, r) {
  let n = "Click";
  return l == "double" ? n = "Double" + n : l == "triple" && (n = "Triple" + n), n = (t == 1 ? "Left" : t == 2 ? "Middle" : "Right") + n, Pt(e, ns(n, r), r, (s) => {
    if (typeof s == "string" && (s = Zt[s]), !s)
      return !1;
    let o = !1;
    try {
      e.isReadOnly() && (e.state.suppressEdits = !0), o = s(e, i) != Ai;
    } finally {
      e.state.suppressEdits = !1;
    }
    return o;
  });
}
function Ma(e, t, i) {
  let l = e.getOption("configureMouse"), r = l ? l(e, t, i) : {};
  if (r.unit == null) {
    let n = Ts ? i.shiftKey && i.metaKey : i.altKey;
    r.unit = n ? "rectangle" : t == "single" ? "char" : t == "double" ? "word" : "line";
  }
  return (r.extend == null || e.doc.extend) && (r.extend = e.doc.extend || i.shiftKey), r.addNew == null && (r.addNew = ne ? i.metaKey : i.ctrlKey), r.moveOnDrag == null && (r.moveOnDrag = !(ne ? i.altKey : i.ctrlKey)), r;
}
function Na(e, t, i, l) {
  N ? setTimeout(yl(Wn, e), 0) : e.curOp.focus = re();
  let r = Ma(e, i, l), n = e.doc.sel, s;
  e.options.dragDrop && Hs && !e.isReadOnly() && i == "single" && (s = n.contains(t)) > -1 && (T((s = n.ranges[s]).from(), t) < 0 || t.xRel > 0) && (T(s.to(), t) > 0 || t.xRel < 0) ? Aa(e, l, t, r) : Da(e, l, t, r);
}
function Aa(e, t, i, l) {
  let r = e.display, n = !1, s = B(e, (u) => {
    $ && (r.scroller.draggable = !1), e.state.draggingText = !1, e.state.delayingBlurEvent && (e.hasFocus() ? e.state.delayingBlurEvent = !1 : zl(e)), te(r.wrapper.ownerDocument, "mouseup", s), te(r.wrapper.ownerDocument, "mousemove", o), te(r.scroller, "dragstart", a), te(r.scroller, "drop", s), n || (j(u), l.addNew || zi(e.doc, i, null, null, l.extend), $ && !Mi || N && F == 9 ? setTimeout(() => {
      r.wrapper.ownerDocument.body.focus({ preventScroll: !0 }), r.input.focus();
    }, 20) : r.input.focus());
  }), o = function(u) {
    n = n || Math.abs(t.clientX - u.clientX) + Math.abs(t.clientY - u.clientY) >= 10;
  }, a = () => n = !0;
  $ && (r.scroller.draggable = !0), e.state.draggingText = s, s.copy = !l.moveOnDrag, S(r.wrapper.ownerDocument, "mouseup", s), S(r.wrapper.ownerDocument, "mousemove", o), S(r.scroller, "dragstart", a), S(r.scroller, "drop", s), e.state.delayingBlurEvent = !0, setTimeout(() => r.input.focus(), 20), r.scroller.dragDrop && r.scroller.dragDrop();
}
function zr(e, t, i) {
  if (i == "char")
    return new H(t, t);
  if (i == "word")
    return e.findWordAt(t);
  if (i == "line")
    return new H(x(t.line, 0), k(e.doc, x(t.line + 1, 0)));
  let l = i(e, t);
  return new H(l.from, l.to);
}
function Da(e, t, i, l) {
  N && zl(e);
  let r = e.display, n = e.doc;
  j(t);
  let s, o, a = n.sel, u = a.ranges;
  if (l.addNew && !l.extend ? (o = n.sel.contains(i), o > -1 ? s = u[o] : s = new H(i, i)) : (s = n.sel.primary(), o = n.sel.primIndex), l.unit == "rectangle")
    l.addNew || (s = new H(i, i)), i = Ke(e, t, !0, !0), o = -1;
  else {
    let y = zr(e, i, l.unit);
    l.extend ? s = ql(s, y.anchor, y.head, l.extend) : s = y;
  }
  l.addNew ? o == -1 ? (o = u.length, U(
    n,
    ue(e, u.concat([s]), o),
    { scroll: !1, origin: "*mouse" }
  )) : u.length > 1 && u[o].empty() && l.unit == "char" && !l.extend ? (U(
    n,
    ue(e, u.slice(0, o).concat(u.slice(o + 1)), 0),
    { scroll: !1, origin: "*mouse" }
  ), a = n.sel) : Zl(n, o, s, Xi) : (o = 0, U(n, new ke([s], 0), Xi), a = n.sel);
  let f = i;
  function h(y) {
    if (T(f, y) != 0)
      if (f = y, l.unit == "rectangle") {
        let L = [], w = e.options.tabSize, M = le(v(n, i.line).text, i.ch, w), A = le(v(n, y.line).text, y.ch, w), D = Math.min(M, A), Q = Math.max(M, A);
        for (let _ = Math.min(i.line, y.line), he = Math.min(e.lastLine(), Math.max(i.line, y.line)); _ <= he; _++) {
          let de = v(n, _).text, V = Qi(de, D, w);
          D == Q ? L.push(new H(x(_, V), x(_, V))) : de.length > V && L.push(new H(x(_, V), x(_, Qi(de, Q, w))));
        }
        L.length || L.push(new H(i, i)), U(
          n,
          ue(e, a.ranges.slice(0, o).concat(L), o),
          { origin: "*mouse", scroll: !1 }
        ), e.scrollIntoView(y);
      } else {
        let L = s, w = zr(e, y, l.unit), M = L.anchor, A;
        T(w.anchor, M) > 0 ? (A = w.head, M = Hi(L.from(), w.anchor)) : (A = w.anchor, M = Wi(L.to(), w.head));
        let D = a.ranges.slice(0);
        D[o] = Oa(e, new H(k(n, M), A)), U(n, ue(e, D, o), Xi);
      }
  }
  let d = r.wrapper.getBoundingClientRect(), c = 0;
  function p(y) {
    let L = ++c, w = Ke(e, y, !0, l.unit == "rectangle");
    if (w)
      if (T(w, f) != 0) {
        e.curOp.focus = re(), h(w);
        let M = wi(r, n);
        (w.line >= M.to || w.line < M.from) && setTimeout(B(e, () => {
          c == L && p(y);
        }), 150);
      } else {
        let M = y.clientY < d.top ? -20 : y.clientY > d.bottom ? 20 : 0;
        M && setTimeout(B(e, () => {
          c == L && (r.scroller.scrollTop += M, p(y));
        }), 50);
      }
  }
  function m(y) {
    e.state.selectingText = !1, c = 1 / 0, y && (j(y), r.input.focus()), te(r.wrapper.ownerDocument, "mousemove", g), te(r.wrapper.ownerDocument, "mouseup", b), n.history.lastSelOrigin = null;
  }
  let g = B(e, (y) => {
    y.buttons === 0 || !Vr(y) ? m(y) : p(y);
  }), b = B(e, m);
  e.state.selectingText = b, S(r.wrapper.ownerDocument, "mousemove", g), S(r.wrapper.ownerDocument, "mouseup", b);
}
function Oa(e, t) {
  let { anchor: i, head: l } = t, r = v(e.doc, i.line);
  if (T(i, l) == 0 && i.sticky == l.sticky)
    return t;
  let n = Le(r);
  if (!n)
    return t;
  let s = zt(n, i.ch, i.sticky), o = n[s];
  if (o.from != i.ch && o.to != i.ch)
    return t;
  let a = s + (o.from == i.ch == (o.level != 1) ? 0 : 1);
  if (a == 0 || a == n.length)
    return t;
  let u;
  if (l.line != i.line)
    u = (l.line - i.line) * (e.doc.direction == "ltr" ? 1 : -1) > 0;
  else {
    let p = zt(n, l.ch, l.sticky), m = p - s || (l.ch - i.ch) * (o.level == 1 ? -1 : 1);
    p == a - 1 || p == a ? u = m < 0 : u = m > 0;
  }
  let f = n[a + (u ? -1 : 0)], h = u == (f.level == 1), d = h ? f.from : f.to, c = h ? "after" : "before";
  return i.ch == d && i.sticky == c ? t : new H(new x(i.line, d, c), l);
}
function cs(e, t, i, l) {
  let r, n;
  if (t.touches)
    r = t.touches[0].clientX, n = t.touches[0].clientY;
  else
    try {
      r = t.clientX, n = t.clientY;
    } catch {
      return !1;
    }
  if (r >= Math.floor(e.display.gutters.getBoundingClientRect().right))
    return !1;
  l && j(t);
  let s = e.display, o = s.lineDiv.getBoundingClientRect();
  if (n > o.bottom || !se(e, i))
    return el(t);
  n -= o.top - s.viewOffset;
  for (let a = 0; a < e.display.gutterSpecs.length; ++a) {
    let u = s.gutters.childNodes[a];
    if (u && u.getBoundingClientRect().right >= r) {
      let f = Ie(e.doc, n), h = e.display.gutterSpecs[a];
      return E(e, i, e, f, h.className, t), el(t);
    }
  }
}
function cl(e, t) {
  return cs(e, t, "gutterClick", !0);
}
function Gr(e, t) {
  Se(e.display, t) || Wa(e, t) || R(e, t, "contextmenu") || gl || e.display.input.onContextMenu(t);
}
function Wa(e, t) {
  return se(e, "gutterContextMenu") ? cs(e, t, "gutterContextMenu", !1) : !1;
}
function ps(e) {
  e.display.wrapper.className = e.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") + e.options.theme.replace(/(^|\s)\s*/g, " cm-s-"), Yt(e);
}
let lt = { toString: function() {
  return "CodeMirror.Init";
} }, gs = {}, ci = {};
function Ha(e) {
  let t = e.optionHandlers;
  function i(l, r, n, s) {
    e.defaults[l] = r, n && (t[l] = s ? (o, a, u) => {
      u != lt && n(o, a, u);
    } : n);
  }
  e.defineOption = i, e.Init = lt, i("value", "", (l, r) => l.setValue(r), !0), i("mode", null, (l, r) => {
    l.doc.modeOption = r, ul(l);
  }, !0), i("indentUnit", 2, ul, !0), i("indentWithTabs", !1), i("smartIndent", !0), i("tabSize", 4, (l) => {
    Mt(l), Yt(l), q(l);
  }, !0), i("lineSeparator", null, (l, r) => {
    if (l.doc.lineSep = r, !r)
      return;
    let n = [], s = l.doc.first;
    l.doc.iter((o) => {
      for (let a = 0; ; ) {
        let u = o.text.indexOf(r, a);
        if (u == -1)
          break;
        a = u + r.length, n.push(x(s, u));
      }
      s++;
    });
    for (let o = n.length - 1; o >= 0; o--)
      wt(l.doc, r, n[o], x(n[o].line, n[o].ch + r.length));
  }), i("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g, (l, r, n) => {
    l.state.specialChars = new RegExp(r.source + (r.test("	") ? "" : "|	"), "g"), n != lt && l.refresh();
  }), i("specialCharPlaceholder", no, (l) => l.refresh(), !0), i("electricChars", !0), i("inputStyle", It ? "contenteditable" : "textarea", () => {
    throw new Error("inputStyle can not (yet) be changed in a running editor");
  }, !0), i("spellcheck", !1, (l, r) => l.getInputField().spellcheck = r, !0), i("autocorrect", !1, (l, r) => l.getInputField().autocorrect = r, !0), i("autocapitalize", !1, (l, r) => l.getInputField().autocapitalize = r, !0), i("rtlMoveVisually", !Ms), i("wholeLineUpdateBefore", !0), i("theme", "default", (l) => {
    ps(l), St(l);
  }, !0), i("keyMap", "default", (l, r, n) => {
    let s = Si(r), o = n != lt && Si(n);
    o && o.detach && o.detach(l, s), s.attach && s.attach(l, o || null);
  }), i("extraKeys", null), i("configureMouse", null), i("lineWrapping", !1, Pa, !0), i("gutters", [], (l, r) => {
    l.display.gutterSpecs = al(r, l.options.lineNumbers), St(l);
  }, !0), i("fixedGutter", !0, (l, r) => {
    l.display.gutters.style.left = r ? Il(l.display) + "px" : "0", l.refresh();
  }, !0), i("coverGutterNextToScrollbar", !1, (l) => dt(l), !0), i("scrollbarStyle", "native", (l) => {
    En(l), dt(l), l.display.scrollbars.setScrollTop(l.doc.scrollTop), l.display.scrollbars.setScrollLeft(l.doc.scrollLeft);
  }, !0), i("lineNumbers", !1, (l, r) => {
    l.display.gutterSpecs = al(l.options.gutters, r), St(l);
  }, !0), i("firstLineNumber", 1, St, !0), i("lineNumberFormatter", (l) => l, St, !0), i("showCursorWhenSelecting", !1, Ot, !0), i("resetSelectionOnContextMenu", !0), i("lineWiseCopyCut", !0), i("pasteLinesPerSelection", !0), i("selectionsMayTouch", !1), i("readOnly", !1, (l, r) => {
    r == "nocursor" && (bt(l), l.display.input.blur()), l.display.input.readOnlyChanged(r);
  }), i("screenReaderLabel", null, (l, r) => {
    r = r === "" ? null : r, l.display.input.screenReaderLabelChanged(r);
  }), i("disableInput", !1, (l, r) => {
    r || l.display.input.reset();
  }, !0), i("dragDrop", !0, Fa), i("allowDropFileTypes", null), i("cursorBlinkRate", 530), i("cursorScrollMargin", 0), i("cursorHeight", 1, Ot, !0), i("singleCursorHeightPerLine", !0, Ot, !0), i("workTime", 100), i("workDelay", 100), i("flattenSpans", !0, Mt, !0), i("addModeClass", !1, Mt, !0), i("pollInterval", 100), i("undoDepth", 200, (l, r) => l.doc.history.undoDepth = r), i("historyEventDelay", 1250), i("viewportMargin", 10, (l) => l.refresh(), !0), i("maxHighlightLength", 1e4, Mt, !0), i("moveInputWithCursor", !0, (l, r) => {
    r || l.display.input.resetPosition();
  }), i("tabindex", null, (l, r) => l.display.input.getField().tabIndex = r || ""), i("autofocus", null), i("direction", "ltr", (l, r) => l.doc.setDirection(r), !0), i("phrases", null);
}
function Fa(e, t, i) {
  let l = i && i != lt;
  if (!t != !l) {
    let r = e.display.dragFunctions, n = t ? S : te;
    n(e.display.scroller, "dragstart", r.start), n(e.display.scroller, "dragenter", r.enter), n(e.display.scroller, "dragover", r.over), n(e.display.scroller, "dragleave", r.leave), n(e.display.scroller, "drop", r.drop);
  }
}
function Pa(e) {
  e.options.lineWrapping ? ($e(e.display.wrapper, "CodeMirror-wrap"), e.display.sizer.style.minWidth = "", e.display.sizerWidth = null) : (Xe(e.display.wrapper, "CodeMirror-wrap"), Al(e)), Rl(e), q(e), Yt(e), setTimeout(() => dt(e), 100);
}
function P(e, t) {
  if (!(this instanceof P))
    return new P(e, t);
  this.options = t = t ? Ue(t) : {}, Ue(gs, t, !1);
  let i = t.value;
  typeof i == "string" ? i = new Y(i, t.mode, null, t.lineSeparator, t.direction) : t.mode && (i.modeOption = t.mode), this.doc = i;
  let l = new P.inputStyles[t.inputStyle](this), r = this.display = new jo(e, i, l, t);
  r.wrapper.CodeMirror = this, ps(this), t.lineWrapping && (this.display.wrapper.className += " CodeMirror-wrap"), En(this), this.state = {
    keyMaps: [],
    // stores maps added by addKeyMap
    overlays: [],
    // highlighting overlays, as added by addOverlay
    modeGen: 0,
    // bumped when mode/overlay changes, used to invalidate highlighting info
    overwrite: !1,
    delayingBlurEvent: !1,
    focused: !1,
    suppressEdits: !1,
    // used to disable editing during key handlers when in readOnly mode
    pasteIncoming: -1,
    cutIncoming: -1,
    // help recognize paste/cut edits in input.poll
    selectingText: !1,
    draggingText: !1,
    highlight: new ft(),
    // stores highlight worker timeout
    keySeq: null,
    // Unfinished key sequence
    specialChars: null
  }, t.autofocus && !It && r.input.focus(), N && F < 11 && setTimeout(() => this.display.input.reset(!0), 20), Ea(this), ca(), qe(this), this.curOp.forceUpdate = !0, _n(this, i), t.autofocus && !It || this.hasFocus() ? setTimeout(() => {
    this.hasFocus() && !this.state.focused && Gl(this);
  }, 20) : bt(this);
  for (let n in ci)
    ci.hasOwnProperty(n) && ci[n](this, t[n], lt);
  zn(this), t.finishInit && t.finishInit(this);
  for (let n = 0; n < pl.length; ++n)
    pl[n](this);
  Ze(this), $ && t.lineWrapping && getComputedStyle(r.lineDiv).textRendering == "optimizelegibility" && (r.lineDiv.style.textRendering = "auto");
}
P.defaults = gs;
P.optionHandlers = ci;
function Ea(e) {
  let t = e.display;
  S(t.scroller, "mousedown", B(e, ds)), N && F < 11 ? S(t.scroller, "dblclick", B(e, (a) => {
    if (R(e, a))
      return;
    let u = Ke(e, a);
    if (!u || cl(e, a) || Se(e.display, a))
      return;
    j(a);
    let f = e.findWordAt(u);
    zi(e.doc, f.anchor, f.head);
  })) : S(t.scroller, "dblclick", (a) => R(e, a) || j(a)), S(t.scroller, "contextmenu", (a) => Gr(e, a)), S(t.input.getField(), "contextmenu", (a) => {
    t.scroller.contains(a.target) || Gr(e, a);
  });
  let i, l = { end: 0 };
  function r() {
    t.activeTouch && (i = setTimeout(() => t.activeTouch = null, 1e3), l = t.activeTouch, l.end = +/* @__PURE__ */ new Date());
  }
  function n(a) {
    if (a.touches.length != 1)
      return !1;
    let u = a.touches[0];
    return u.radiusX <= 1 && u.radiusY <= 1;
  }
  function s(a, u) {
    if (u.left == null)
      return !0;
    let f = u.left - a.left, h = u.top - a.top;
    return f * f + h * h > 20 * 20;
  }
  S(t.scroller, "touchstart", (a) => {
    if (!R(e, a) && !n(a) && !cl(e, a)) {
      t.input.ensurePolled(), clearTimeout(i);
      let u = +/* @__PURE__ */ new Date();
      t.activeTouch = {
        start: u,
        moved: !1,
        prev: u - l.end <= 300 ? l : null
      }, a.touches.length == 1 && (t.activeTouch.left = a.touches[0].pageX, t.activeTouch.top = a.touches[0].pageY);
    }
  }), S(t.scroller, "touchmove", () => {
    t.activeTouch && (t.activeTouch.moved = !0);
  }), S(t.scroller, "touchend", (a) => {
    let u = t.activeTouch;
    if (u && !Se(t, a) && u.left != null && !u.moved && /* @__PURE__ */ new Date() - u.start < 300) {
      let f = e.coordsChar(t.activeTouch, "page"), h;
      !u.prev || s(u, u.prev) ? h = new H(f, f) : !u.prev.prev || s(u, u.prev.prev) ? h = e.findWordAt(f) : h = new H(x(f.line, 0), k(e.doc, x(f.line + 1, 0))), e.setSelection(h.anchor, h.head), e.focus(), j(a);
    }
    r();
  }), S(t.scroller, "touchcancel", r), S(t.scroller, "scroll", () => {
    t.scroller.clientHeight && (Vt(e, t.scroller.scrollTop), je(e, t.scroller.scrollLeft, !0), E(e, "scroll", e));
  }), S(t.scroller, "mousewheel", (a) => vr(e, a)), S(t.scroller, "DOMMouseScroll", (a) => vr(e, a)), S(t.wrapper, "scroll", () => t.wrapper.scrollTop = t.wrapper.scrollLeft = 0), t.dragFunctions = {
    enter: (a) => {
      R(e, a) || Gt(a);
    },
    over: (a) => {
      R(e, a) || (da(e, a), Gt(a));
    },
    start: (a) => ha(e, a),
    drop: B(e, fa),
    leave: (a) => {
      R(e, a) || ls(e);
    }
  };
  let o = t.input.getField();
  S(o, "keyup", (a) => fs.call(e, a)), S(o, "keydown", B(e, us)), S(o, "keypress", B(e, hs)), S(o, "focus", (a) => Gl(e, a)), S(o, "blur", (a) => bt(e, a));
}
let pl = [];
P.defineInitHook = (e) => pl.push(e);
function Et(e, t, i, l) {
  let r = e.doc, n;
  i == null && (i = "add"), i == "smart" && (r.mode.indent ? n = Jt(e, t).state : i = "prev");
  let s = e.options.tabSize, o = v(r, t), a = le(o.text, null, s);
  o.stateAfter && (o.stateAfter = null);
  let u = o.text.match(/^\s*/)[0], f;
  if (!l && !/\S/.test(o.text))
    f = 0, i = "not";
  else if (i == "smart" && (f = r.mode.indent(n, o.text.slice(u.length), o.text), f == Ai || f > 150)) {
    if (!l)
      return;
    i = "prev";
  }
  i == "prev" ? t > r.first ? f = le(v(r, t - 1).text, null, s) : f = 0 : i == "add" ? f = a + e.options.indentUnit : i == "subtract" ? f = a - e.options.indentUnit : typeof i == "number" && (f = a + i), f = Math.max(0, f);
  let h = "", d = 0;
  if (e.options.indentWithTabs)
    for (let c = Math.floor(f / s); c; --c)
      d += s, h += "	";
  if (d < f && (h += ml(f - d)), h != u)
    return wt(r, h, x(t, 0), x(t, u.length), "+input"), o.stateAfter = null, !0;
  for (let c = 0; c < r.sel.ranges.length; c++) {
    let p = r.sel.ranges[c];
    if (p.head.line == t && p.head.ch < u.length) {
      let m = x(t, u.length);
      Zl(r, c, new H(m, m));
      break;
    }
  }
}
let oe = null;
function Li(e) {
  oe = e;
}
function ir(e, t, i, l, r) {
  let n = e.doc;
  e.display.shift = !1, l || (l = n.sel);
  let s = +/* @__PURE__ */ new Date() - 200, o = r == "paste" || e.state.pasteIncoming > s, a = wl(t), u = null;
  if (o && l.ranges.length > 1)
    if (oe && oe.text.join(`
`) == t) {
      if (l.ranges.length % oe.text.length == 0) {
        u = [];
        for (let h = 0; h < oe.text.length; h++)
          u.push(n.splitLines(oe.text[h]));
      }
    } else
      a.length == l.ranges.length && e.options.pasteLinesPerSelection && (u = Di(a, (h) => [h]));
  let f = e.curOp.updateInput;
  for (let h = l.ranges.length - 1; h >= 0; h--) {
    let d = l.ranges[h], c = d.from(), p = d.to();
    d.empty() && (i && i > 0 ? c = x(c.line, c.ch - i) : e.state.overwrite && !o ? p = x(p.line, Math.min(v(n, p.line).text.length, p.ch + O(a).length)) : o && oe && oe.lineWise && oe.text.join(`
`) == a.join(`
`) && (c = p = x(c.line, 0)));
    let m = {
      from: c,
      to: p,
      text: u ? u[h % u.length] : a,
      origin: r || (o ? "paste" : e.state.cutIncoming > s ? "cut" : "+input")
    };
    ct(e.doc, m), z(e, "inputRead", e, m);
  }
  t && !o && ms(e, t), xt(e), e.curOp.updateInput < 2 && (e.curOp.updateInput = f), e.curOp.typing = !0, e.state.pasteIncoming = e.state.cutIncoming = -1;
}
function ys(e, t) {
  let i = e.clipboardData && e.clipboardData.getData("Text");
  if (i)
    return e.preventDefault(), !t.isReadOnly() && !t.options.disableInput && J(t, () => ir(t, i, 0, null, "paste")), !0;
}
function ms(e, t) {
  if (!e.options.electricChars || !e.options.smartIndent)
    return;
  let i = e.doc.sel;
  for (let l = i.ranges.length - 1; l >= 0; l--) {
    let r = i.ranges[l];
    if (r.head.ch > 100 || l && i.ranges[l - 1].head.line == r.head.line)
      continue;
    let n = e.getModeAt(r.head), s = !1;
    if (n.electricChars) {
      for (let o = 0; o < n.electricChars.length; o++)
        if (t.indexOf(n.electricChars.charAt(o)) > -1) {
          s = Et(e, r.head.line, "smart");
          break;
        }
    } else
      n.electricInput && n.electricInput.test(v(e.doc, r.head.line).text.slice(0, r.head.ch)) && (s = Et(e, r.head.line, "smart"));
    s && z(e, "electricInput", e, r.head.line);
  }
}
function bs(e) {
  let t = [], i = [];
  for (let l = 0; l < e.doc.sel.ranges.length; l++) {
    let r = e.doc.sel.ranges[l].head.line, n = { anchor: x(r, 0), head: x(r + 1, 0) };
    i.push(n), t.push(e.getRange(n.anchor, n.head));
  }
  return { text: t, ranges: i };
}
function xs(e, t, i, l) {
  e.setAttribute("autocorrect", i ? "" : "off"), e.setAttribute("autocapitalize", l ? "" : "off"), e.setAttribute("spellcheck", !!t);
}
function ws() {
  let e = C("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none"), t = C("div", [e], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
  return $ ? e.style.width = "1000px" : e.setAttribute("wrap", "off"), Qt && (e.style.border = "1px solid black"), xs(e), t;
}
function Ia(e) {
  let t = e.optionHandlers, i = e.helpers = {};
  e.prototype = {
    constructor: e,
    focus: function() {
      window.focus(), this.display.input.focus();
    },
    setOption: function(l, r) {
      let n = this.options, s = n[l];
      n[l] == r && l != "mode" || (n[l] = r, t.hasOwnProperty(l) && B(this, t[l])(this, r, s), E(this, "optionChange", this, l));
    },
    getOption: function(l) {
      return this.options[l];
    },
    getDoc: function() {
      return this.doc;
    },
    addKeyMap: function(l, r) {
      this.state.keyMaps[r ? "push" : "unshift"](Si(l));
    },
    removeKeyMap: function(l) {
      let r = this.state.keyMaps;
      for (let n = 0; n < r.length; ++n)
        if (r[n] == l || r[n].name == l)
          return r.splice(n, 1), !0;
    },
    addOverlay: X(function(l, r) {
      let n = l.token ? l : e.getMode(this.options, l);
      if (n.startState)
        throw new Error("Overlays may not be stateful.");
      Ns(
        this.state.overlays,
        {
          mode: n,
          modeSpec: l,
          opaque: r && r.opaque,
          priority: r && r.priority || 0
        },
        (s) => s.priority
      ), this.state.modeGen++, q(this);
    }),
    removeOverlay: X(function(l) {
      let r = this.state.overlays;
      for (let n = 0; n < r.length; ++n) {
        let s = r[n].modeSpec;
        if (s == l || typeof l == "string" && s.name == l) {
          r.splice(n, 1), this.state.modeGen++, q(this);
          return;
        }
      }
    }),
    indentLine: X(function(l, r, n) {
      typeof r != "string" && typeof r != "number" && (r == null ? r = this.options.smartIndent ? "smart" : "prev" : r = r ? "add" : "subtract"), Ut(this.doc, l) && Et(this, l, r, n);
    }),
    indentSelection: X(function(l) {
      let r = this.doc.sel.ranges, n = -1;
      for (let s = 0; s < r.length; s++) {
        let o = r[s];
        if (o.empty())
          o.head.line > n && (Et(this, o.head.line, l, !0), n = o.head.line, s == this.doc.sel.primIndex && xt(this));
        else {
          let a = o.from(), u = o.to(), f = Math.max(n, a.line);
          n = Math.min(this.lastLine(), u.line - (u.ch ? 0 : 1)) + 1;
          for (let d = f; d < n; ++d)
            Et(this, d, l);
          let h = this.doc.sel.ranges;
          a.ch == 0 && r.length == h.length && h[s].from().ch > 0 && Zl(this.doc, s, new H(a, h[s].to()), ce);
        }
      }
    }),
    // Fetch the parser token for a given character. Useful for hacks
    // that want to inspect the mode state (say, for completion).
    getTokenAt: function(l, r) {
      return ar(this, l, r);
    },
    getLineTokens: function(l, r) {
      return ar(this, x(l), r, !0);
    },
    getTokenTypeAt: function(l) {
      l = k(this.doc, l);
      let r = rn(this, v(this.doc, l.line)), n = 0, s = (r.length - 1) / 2, o = l.ch, a;
      if (o == 0)
        a = r[2];
      else
        for (; ; ) {
          let f = n + s >> 1;
          if ((f ? r[f * 2 - 1] : 0) >= o)
            s = f;
          else if (r[f * 2 + 1] < o)
            n = f + 1;
          else {
            a = r[f * 2 + 2];
            break;
          }
        }
      let u = a ? a.indexOf("overlay ") : -1;
      return u < 0 ? a : u == 0 ? null : a.slice(0, u - 1);
    },
    getModeAt: function(l) {
      let r = this.doc.mode;
      return r.innerMode ? e.innerMode(r, this.getTokenAt(l).state).mode : r;
    },
    getHelper: function(l, r) {
      return this.getHelpers(l, r)[0];
    },
    getHelpers: function(l, r) {
      let n = [];
      if (!i.hasOwnProperty(r))
        return n;
      let s = i[r], o = this.getModeAt(l);
      if (typeof o[r] == "string")
        s[o[r]] && n.push(s[o[r]]);
      else if (o[r])
        for (let a = 0; a < o[r].length; a++) {
          let u = s[o[r][a]];
          u && n.push(u);
        }
      else
        o.helperType && s[o.helperType] ? n.push(s[o.helperType]) : s[o.name] && n.push(s[o.name]);
      for (let a = 0; a < s._global.length; a++) {
        let u = s._global[a];
        u.pred(o, this) && K(n, u.val) == -1 && n.push(u.val);
      }
      return n;
    },
    getStateAfter: function(l, r) {
      let n = this.doc;
      return l = tn(n, l == null ? n.first + n.size - 1 : l), Jt(this, l + 1, r).state;
    },
    cursorCoords: function(l, r) {
      let n, s = this.doc.sel.primary();
      return l == null ? n = s.head : typeof l == "object" ? n = k(this.doc, l) : n = l ? s.from() : s.to(), ae(this, n, r || "page");
    },
    charCoords: function(l, r) {
      return xi(this, k(this.doc, l), r || "page");
    },
    coordsChar: function(l, r) {
      return l = yr(this, l, r || "page"), Pl(this, l.left, l.top);
    },
    lineAtHeight: function(l, r) {
      return l = yr(this, { top: l, left: 0 }, r || "page").top, Ie(this.doc, l + this.display.viewOffset);
    },
    heightAtLine: function(l, r, n) {
      let s = !1, o;
      if (typeof l == "number") {
        let a = this.doc.first + this.doc.size - 1;
        l < this.doc.first ? l = this.doc.first : l > a && (l = a, s = !0), o = v(this.doc, l);
      } else
        o = l;
      return Ii(this, o, { top: 0, left: 0 }, r || "page", n || s).top + (s ? this.doc.height - Ce(o) : 0);
    },
    defaultTextHeight: function() {
      return ht(this.display);
    },
    defaultCharWidth: function() {
      return mt(this.display);
    },
    getViewport: function() {
      return { from: this.display.viewFrom, to: this.display.viewTo };
    },
    addWidget: function(l, r, n, s, o) {
      let a = this.display;
      l = ae(this, k(this.doc, l));
      let u = l.bottom, f = l.left;
      if (r.style.position = "absolute", r.setAttribute("cm-ignore-events", "true"), this.display.input.setUneditable(r), a.sizer.appendChild(r), s == "over")
        u = l.top;
      else if (s == "above" || s == "near") {
        let h = Math.max(a.wrapper.clientHeight, this.doc.height), d = Math.max(a.sizer.clientWidth, a.lineSpace.clientWidth);
        (s == "above" || l.bottom + r.offsetHeight > h) && l.top > r.offsetHeight ? u = l.top - r.offsetHeight : l.bottom + r.offsetHeight <= h && (u = l.bottom), f + r.offsetWidth > d && (f = d - r.offsetWidth);
      }
      r.style.top = u + "px", r.style.left = r.style.right = "", o == "right" ? (f = a.sizer.clientWidth - r.offsetWidth, r.style.right = "0px") : (o == "left" ? f = 0 : o == "middle" && (f = (a.sizer.clientWidth - r.offsetWidth) / 2), r.style.left = f + "px"), n && Wo(this, { left: f, top: u, right: f + r.offsetWidth, bottom: u + r.offsetHeight });
    },
    triggerOnKeyDown: X(us),
    triggerOnKeyPress: X(hs),
    triggerOnKeyUp: fs,
    triggerOnMouseDown: X(ds),
    execCommand: function(l) {
      if (Zt.hasOwnProperty(l))
        return Zt[l].call(null, this);
    },
    triggerElectric: X(function(l) {
      ms(this, l);
    }),
    findPosH: function(l, r, n, s) {
      let o = 1;
      r < 0 && (o = -1, r = -r);
      let a = k(this.doc, l);
      for (let u = 0; u < r && (a = Zi(this.doc, a, o, n, s), !a.hitSide); ++u)
        ;
      return a;
    },
    moveH: X(function(l, r) {
      this.extendSelectionsBy((n) => this.display.shift || this.doc.extend || n.empty() ? Zi(this.doc, n.head, l, r, this.options.rtlMoveVisually) : l < 0 ? n.from() : n.to(), At);
    }),
    deleteH: X(function(l, r) {
      let n = this.doc.sel, s = this.doc;
      n.somethingSelected() ? s.replaceSelection("", null, "+delete") : Ve(this, (o) => {
        let a = Zi(s, o.head, l, r, !1);
        return l < 0 ? { from: a, to: o.head } : { from: o.head, to: a };
      });
    }),
    findPosV: function(l, r, n, s) {
      let o = 1, a = s;
      r < 0 && (o = -1, r = -r);
      let u = k(this.doc, l);
      for (let f = 0; f < r; ++f) {
        let h = ae(this, u, "div");
        if (a == null ? a = h.left : h.left = a, u = Ur(this, h, o, n), u.hitSide)
          break;
      }
      return u;
    },
    moveV: X(function(l, r) {
      let n = this.doc, s = [], o = !this.display.shift && !n.extend && n.sel.somethingSelected();
      if (n.extendSelectionsBy((a) => {
        if (o)
          return l < 0 ? a.from() : a.to();
        let u = ae(this, a.head, "div");
        a.goalColumn != null && (u.left = a.goalColumn), s.push(u.left);
        let f = Ur(this, u, l, r);
        return r == "page" && a == n.sel.primary() && Kl(this, xi(this, f, "div").top - u.top), f;
      }, At), s.length)
        for (let a = 0; a < n.sel.ranges.length; a++)
          n.sel.ranges[a].goalColumn = s[a];
    }),
    // Find the word at the given position (as returned by coordsChar).
    findWordAt: function(l) {
      let r = this.doc, n = v(r, l.line).text, s = l.ch, o = l.ch;
      if (n) {
        let a = this.getHelper(l, "wordChars");
        (l.sticky == "before" || o == n.length) && s ? --s : ++o;
        let u = n.charAt(s), f = ui(u, a) ? (h) => ui(h, a) : /\s/.test(u) ? (h) => /\s/.test(h) : (h) => !/\s/.test(h) && !ui(h);
        for (; s > 0 && f(n.charAt(s - 1)); )
          --s;
        for (; o < n.length && f(n.charAt(o)); )
          ++o;
      }
      return new H(x(l.line, s), x(l.line, o));
    },
    toggleOverwrite: function(l) {
      l != null && l == this.state.overwrite || ((this.state.overwrite = !this.state.overwrite) ? $e(this.display.cursorDiv, "CodeMirror-overwrite") : Xe(this.display.cursorDiv, "CodeMirror-overwrite"), E(this, "overwriteToggle", this, this.state.overwrite));
    },
    hasFocus: function() {
      return this.display.input.getField() == re();
    },
    isReadOnly: function() {
      return !!(this.options.readOnly || this.doc.cantEdit);
    },
    scrollTo: X(function(l, r) {
      Wt(this, l, r);
    }),
    getScrollInfo: function() {
      let l = this.display.scroller;
      return {
        left: l.scrollLeft,
        top: l.scrollTop,
        height: l.scrollHeight - ye(this) - this.display.barHeight,
        width: l.scrollWidth - ye(this) - this.display.barWidth,
        clientHeight: Wl(this),
        clientWidth: Ye(this)
      };
    },
    scrollIntoView: X(function(l, r) {
      l == null ? (l = { from: this.doc.sel.primary().head, to: null }, r == null && (r = this.options.cursorScrollMargin)) : typeof l == "number" ? l = { from: x(l, 0), to: null } : l.from == null && (l = { from: l, to: null }), l.to || (l.to = l.from), l.margin = r || 0, l.from.line != null ? Ho(this, l) : Hn(this, l.from, l.to, l.margin);
    }),
    setSize: X(function(l, r) {
      let n = (o) => typeof o == "number" || /^\d+$/.test(String(o)) ? o + "px" : o;
      l != null && (this.display.wrapper.style.width = n(l)), r != null && (this.display.wrapper.style.height = n(r)), this.options.lineWrapping && Ln(this);
      let s = this.display.viewFrom;
      this.doc.iter(s, this.display.viewTo, (o) => {
        if (o.widgets) {
          for (let a = 0; a < o.widgets.length; a++)
            if (o.widgets[a].noHScroll) {
              Fe(this, s, "widget");
              break;
            }
        }
        ++s;
      }), this.curOp.forceUpdate = !0, E(this, "refresh", this);
    }),
    operation: function(l) {
      return J(this, l);
    },
    startOperation: function() {
      return qe(this);
    },
    endOperation: function() {
      return Ze(this);
    },
    refresh: X(function() {
      let l = this.display.cachedTextHeight;
      q(this), this.curOp.forceUpdate = !0, Yt(this), Wt(this, this.doc.scrollLeft, this.doc.scrollTop), Xl(this.display), (l == null || Math.abs(l - ht(this.display)) > 0.5 || this.options.lineWrapping) && Rl(this), E(this, "refresh", this);
    }),
    swapDoc: X(function(l) {
      let r = this.doc;
      return r.cm = null, this.state.selectingText && this.state.selectingText(), _n(this, l), Yt(this), this.display.input.reset(), Wt(this, l.scrollLeft, l.scrollTop), this.curOp.forceScroll = !0, z(this, "swapDoc", this, r), r;
    }),
    phrase: function(l) {
      let r = this.options.phrases;
      return r && Object.prototype.hasOwnProperty.call(r, l) ? r[l] : l;
    },
    getInputField: function() {
      return this.display.input.getField();
    },
    getWrapperElement: function() {
      return this.display.wrapper;
    },
    getScrollerElement: function() {
      return this.display.scroller;
    },
    getGutterElement: function() {
      return this.display.gutters;
    }
  }, gt(e), e.registerHelper = function(l, r, n) {
    i.hasOwnProperty(l) || (i[l] = e[l] = { _global: [] }), i[l][r] = n;
  }, e.registerGlobalHelper = function(l, r, n, s) {
    e.registerHelper(l, r, s), i[l]._global.push({ pred: n, val: s });
  };
}
function Zi(e, t, i, l, r) {
  let n = t, s = i, o = v(e, t.line), a = r && e.direction == "rtl" ? -i : i;
  function u() {
    let d = t.line + a;
    return d < e.first || d >= e.first + e.size ? !1 : (t = new x(d, t.ch, t.sticky), o = v(e, d));
  }
  function f(d) {
    let c;
    if (l == "codepoint") {
      let p = o.text.charCodeAt(t.ch + (i > 0 ? 0 : -1));
      if (isNaN(p))
        c = null;
      else {
        let m = i > 0 ? p >= 55296 && p < 56320 : p >= 56320 && p < 57343;
        c = new x(t.line, Math.max(0, Math.min(o.text.length, t.ch + i * (m ? 2 : 1))), -i);
      }
    } else
      r ? c = ba(e.cm, o, t, i) : c = hl(o, t, i);
    if (c == null)
      if (!d && u())
        t = tr(r, e.cm, o, t.line, a);
      else
        return !1;
    else
      t = c;
    return !0;
  }
  if (l == "char" || l == "codepoint")
    f();
  else if (l == "column")
    f(!0);
  else if (l == "word" || l == "group") {
    let d = null, c = l == "group", p = e.cm && e.cm.getHelper(t, "wordChars");
    for (let m = !0; !(i < 0 && !f(!m)); m = !1) {
      let g = o.text.charAt(t.ch) || `
`, b = ui(g, p) ? "w" : c && g == `
` ? "n" : !c || /\s/.test(g) ? null : "p";
      if (c && !m && !b && (b = "s"), d && d != b) {
        i < 0 && (i = 1, f(), t.sticky = "after");
        break;
      }
      if (b && (d = b), i > 0 && !f(!m))
        break;
    }
  }
  let h = Ci(e, t, n, s, !0);
  return tl(n, h) && (h.hitSide = !0), h;
}
function Ur(e, t, i, l) {
  let r = e.doc, n = t.left, s;
  if (l == "page") {
    let a = Math.min(e.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight), u = Math.max(a - 0.5 * ht(e.display), 3);
    s = (i > 0 ? t.bottom : t.top) + i * u;
  } else
    l == "line" && (s = i > 0 ? t.bottom + 3 : t.top - 3);
  let o;
  for (; o = Pl(e, n, s), !!o.outside; ) {
    if (i < 0 ? s <= 0 : s >= r.height) {
      o.hitSide = !0;
      break;
    }
    s += i * 5;
  }
  return o;
}
class vs {
  constructor(t) {
    this.cm = t, this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null, this.polling = new ft(), this.composing = null, this.gracePeriod = !1, this.readDOMTimeout = null;
  }
  init(t) {
    let i = this, l = i.cm, r = i.div = t.lineDiv;
    r.contentEditable = !0, xs(r, l.options.spellcheck, l.options.autocorrect, l.options.autocapitalize);
    function n(o) {
      for (let a = o.target; a; a = a.parentNode) {
        if (a == r)
          return !0;
        if (/\bCodeMirror-(?:line)?widget\b/.test(a.className))
          break;
      }
      return !1;
    }
    S(r, "paste", (o) => {
      !n(o) || R(l, o) || ys(o, l) || F <= 11 && setTimeout(B(l, () => this.updateFromDOM()), 20);
    }), S(r, "compositionstart", (o) => {
      this.composing = { data: o.data, done: !1 };
    }), S(r, "compositionupdate", (o) => {
      this.composing || (this.composing = { data: o.data, done: !1 });
    }), S(r, "compositionend", (o) => {
      this.composing && (o.data != this.composing.data && this.readFromDOMSoon(), this.composing.done = !0);
    }), S(r, "touchstart", () => i.forceCompositionEnd()), S(r, "input", () => {
      this.composing || this.readFromDOMSoon();
    });
    function s(o) {
      if (!n(o) || R(l, o))
        return;
      if (l.somethingSelected())
        Li({ lineWise: !1, text: l.getSelections() }), o.type == "cut" && l.replaceSelection("", null, "cut");
      else if (l.options.lineWiseCopyCut) {
        let h = bs(l);
        Li({ lineWise: !0, text: h.text }), o.type == "cut" && l.operation(() => {
          l.setSelections(h.ranges, 0, ce), l.replaceSelection("", null, "cut");
        });
      } else
        return;
      if (o.clipboardData) {
        o.clipboardData.clearData();
        let h = oe.text.join(`
`);
        if (o.clipboardData.setData("Text", h), o.clipboardData.getData("Text") == h) {
          o.preventDefault();
          return;
        }
      }
      let a = ws(), u = a.firstChild;
      l.display.lineSpace.insertBefore(a, l.display.lineSpace.firstChild), u.value = oe.text.join(`
`);
      let f = re();
      Rt(u), setTimeout(() => {
        l.display.lineSpace.removeChild(a), f.focus(), f == r && i.showPrimarySelection();
      }, 50);
    }
    S(r, "copy", s), S(r, "cut", s);
  }
  screenReaderLabelChanged(t) {
    t ? this.div.setAttribute("aria-label", t) : this.div.removeAttribute("aria-label");
  }
  prepareSelection() {
    let t = Dn(this.cm, !1);
    return t.focus = re() == this.div, t;
  }
  showSelection(t, i) {
    !t || !this.cm.display.view.length || ((t.focus || i) && this.showPrimarySelection(), this.showMultipleSelections(t));
  }
  getSelection() {
    return this.cm.display.wrapper.ownerDocument.getSelection();
  }
  showPrimarySelection() {
    let t = this.getSelection(), i = this.cm, l = i.doc.sel.primary(), r = l.from(), n = l.to();
    if (i.display.viewTo == i.display.viewFrom || r.line >= i.display.viewTo || n.line < i.display.viewFrom) {
      t.removeAllRanges();
      return;
    }
    let s = ai(i, t.anchorNode, t.anchorOffset), o = ai(i, t.focusNode, t.focusOffset);
    if (s && !s.bad && o && !o.bad && T(Hi(s, o), r) == 0 && T(Wi(s, o), n) == 0)
      return;
    let a = i.display.view, u = r.line >= i.display.viewFrom && Kr(i, r) || { node: a[0].measure.map[2], offset: 0 }, f = n.line < i.display.viewTo && Kr(i, n);
    if (!f) {
      let c = a[a.length - 1].measure, p = c.maps ? c.maps[c.maps.length - 1] : c.map;
      f = { node: p[p.length - 1], offset: p[p.length - 2] - p[p.length - 3] };
    }
    if (!u || !f) {
      t.removeAllRanges();
      return;
    }
    let h = t.rangeCount && t.getRangeAt(0), d;
    try {
      d = Ge(u.node, u.offset, f.offset, f.node);
    } catch {
    }
    d && (!we && i.state.focused ? (t.collapse(u.node, u.offset), d.collapsed || (t.removeAllRanges(), t.addRange(d))) : (t.removeAllRanges(), t.addRange(d)), h && t.anchorNode == null ? t.addRange(h) : we && this.startGracePeriod()), this.rememberSelection();
  }
  startGracePeriod() {
    clearTimeout(this.gracePeriod), this.gracePeriod = setTimeout(() => {
      this.gracePeriod = !1, this.selectionChanged() && this.cm.operation(() => this.cm.curOp.selectionChanged = !0);
    }, 20);
  }
  showMultipleSelections(t) {
    ie(this.cm.display.cursorDiv, t.cursors), ie(this.cm.display.selectionDiv, t.selection);
  }
  rememberSelection() {
    let t = this.getSelection();
    this.lastAnchorNode = t.anchorNode, this.lastAnchorOffset = t.anchorOffset, this.lastFocusNode = t.focusNode, this.lastFocusOffset = t.focusOffset;
  }
  selectionInEditor() {
    let t = this.getSelection();
    if (!t.rangeCount)
      return !1;
    let i = t.getRangeAt(0).commonAncestorContainer;
    return Ae(this.div, i);
  }
  focus() {
    this.cm.options.readOnly != "nocursor" && ((!this.selectionInEditor() || re() != this.div) && this.showSelection(this.prepareSelection(), !0), this.div.focus());
  }
  blur() {
    this.div.blur();
  }
  getField() {
    return this.div;
  }
  supportsTouch() {
    return !0;
  }
  receivedFocus() {
    let t = this;
    this.selectionInEditor() ? setTimeout(() => this.pollSelection(), 20) : J(this.cm, () => t.cm.curOp.selectionChanged = !0);
    function i() {
      t.cm.state.focused && (t.pollSelection(), t.polling.set(t.cm.options.pollInterval, i));
    }
    this.polling.set(this.cm.options.pollInterval, i);
  }
  selectionChanged() {
    let t = this.getSelection();
    return t.anchorNode != this.lastAnchorNode || t.anchorOffset != this.lastAnchorOffset || t.focusNode != this.lastFocusNode || t.focusOffset != this.lastFocusOffset;
  }
  pollSelection() {
    if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged())
      return;
    let t = this.getSelection(), i = this.cm;
    if (Ni && Ti && this.cm.display.gutterSpecs.length && Ra(t.anchorNode)) {
      this.cm.triggerOnKeyDown({ type: "keydown", keyCode: 8, preventDefault: Math.abs }), this.blur(), this.focus();
      return;
    }
    if (this.composing)
      return;
    this.rememberSelection();
    let l = ai(i, t.anchorNode, t.anchorOffset), r = ai(i, t.focusNode, t.focusOffset);
    l && r && J(i, () => {
      U(i.doc, Oe(l, r), ce), (l.bad || r.bad) && (i.curOp.selectionChanged = !0);
    });
  }
  pollContent() {
    this.readDOMTimeout != null && (clearTimeout(this.readDOMTimeout), this.readDOMTimeout = null);
    let t = this.cm, i = t.display, l = t.doc.sel.primary(), r = l.from(), n = l.to();
    if (r.ch == 0 && r.line > t.firstLine() && (r = x(r.line - 1, v(t.doc, r.line - 1).length)), n.ch == v(t.doc, n.line).text.length && n.line < t.lastLine() && (n = x(n.line + 1, 0)), r.line < i.viewFrom || n.line > i.viewTo - 1)
      return !1;
    let s, o, a;
    r.line == i.viewFrom || (s = _e(t, r.line)) == 0 ? (o = W(i.view[0].line), a = i.view[0].node) : (o = W(i.view[s].line), a = i.view[s - 1].node.nextSibling);
    let u = _e(t, n.line), f, h;
    if (u == i.view.length - 1 ? (f = i.viewTo - 1, h = i.lineDiv.lastChild) : (f = W(i.view[u + 1].line) - 1, h = i.view[u + 1].node.previousSibling), !a)
      return !1;
    let d = t.doc.splitLines(Ba(t, a, h, o, f)), c = ze(t.doc, x(o, 0), x(f, v(t.doc, f).text.length));
    for (; d.length > 1 && c.length > 1; )
      if (O(d) == O(c))
        d.pop(), c.pop(), f--;
      else if (d[0] == c[0])
        d.shift(), c.shift(), o++;
      else
        break;
    let p = 0, m = 0, g = d[0], b = c[0], y = Math.min(g.length, b.length);
    for (; p < y && g.charCodeAt(p) == b.charCodeAt(p); )
      ++p;
    let L = O(d), w = O(c), M = Math.min(
      L.length - (d.length == 1 ? p : 0),
      w.length - (c.length == 1 ? p : 0)
    );
    for (; m < M && L.charCodeAt(L.length - m - 1) == w.charCodeAt(w.length - m - 1); )
      ++m;
    if (d.length == 1 && c.length == 1 && o == r.line)
      for (; p && p > r.ch && L.charCodeAt(L.length - m - 1) == w.charCodeAt(w.length - m - 1); )
        p--, m++;
    d[d.length - 1] = L.slice(0, L.length - m).replace(/^\u200b+/, ""), d[0] = d[0].slice(p).replace(/\u200b+$/, "");
    let A = x(o, p), D = x(f, c.length ? O(c).length - m : 0);
    if (d.length > 1 || d[0] || T(A, D))
      return wt(t.doc, d, A, D, "+input"), !0;
  }
  ensurePolled() {
    this.forceCompositionEnd();
  }
  reset() {
    this.forceCompositionEnd();
  }
  forceCompositionEnd() {
    this.composing && (clearTimeout(this.readDOMTimeout), this.composing = null, this.updateFromDOM(), this.div.blur(), this.div.focus());
  }
  readFromDOMSoon() {
    this.readDOMTimeout == null && (this.readDOMTimeout = setTimeout(() => {
      if (this.readDOMTimeout = null, this.composing)
        if (this.composing.done)
          this.composing = null;
        else
          return;
      this.updateFromDOM();
    }, 80));
  }
  updateFromDOM() {
    (this.cm.isReadOnly() || !this.pollContent()) && J(this.cm, () => q(this.cm));
  }
  setUneditable(t) {
    t.contentEditable = "false";
  }
  onKeyPress(t) {
    t.charCode == 0 || this.composing || (t.preventDefault(), this.cm.isReadOnly() || B(this.cm, ir)(this.cm, String.fromCharCode(t.charCode == null ? t.keyCode : t.charCode), 0));
  }
  readOnlyChanged(t) {
    this.div.contentEditable = String(t != "nocursor");
  }
  onContextMenu() {
  }
  resetPosition() {
  }
}
vs.prototype.needsContentAttribute = !0;
function Kr(e, t) {
  let i = Hl(e, t.line);
  if (!i || i.hidden)
    return null;
  let l = v(e.doc, t.line), r = xn(i, l, t.line), n = Le(l, e.doc.direction), s = "left";
  n && (s = zt(n, t.ch) % 2 ? "right" : "left");
  let o = Cn(r.map, t.ch, s);
  return o.offset = o.collapse == "right" ? o.end : o.start, o;
}
function Ra(e) {
  for (let t = e; t; t = t.parentNode)
    if (/CodeMirror-gutter-wrapper/.test(t.className))
      return !0;
  return !1;
}
function et(e, t) {
  return t && (e.bad = !0), e;
}
function Ba(e, t, i, l, r) {
  let n = "", s = !1, o = e.doc.lineSeparator(), a = !1;
  function u(c) {
    return (p) => p.id == c;
  }
  function f() {
    s && (n += o, a && (n += o), s = a = !1);
  }
  function h(c) {
    c && (f(), n += c);
  }
  function d(c) {
    if (c.nodeType == 1) {
      let p = c.getAttribute("cm-text");
      if (p) {
        h(p);
        return;
      }
      let m = c.getAttribute("cm-marker"), g;
      if (m) {
        let y = e.findMarks(x(l, 0), x(r + 1, 0), u(+m));
        y.length && (g = y[0].find(0)) && h(ze(e.doc, g.from, g.to).join(o));
        return;
      }
      if (c.getAttribute("contenteditable") == "false")
        return;
      let b = /^(pre|div|p|li|table|br)$/i.test(c.nodeName);
      if (!/^br$/i.test(c.nodeName) && c.textContent.length == 0)
        return;
      b && f();
      for (let y = 0; y < c.childNodes.length; y++)
        d(c.childNodes[y]);
      /^(pre|p)$/i.test(c.nodeName) && (a = !0), b && (s = !0);
    } else
      c.nodeType == 3 && h(c.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "));
  }
  for (; d(t), t != i; )
    t = t.nextSibling, a = !1;
  return n;
}
function ai(e, t, i) {
  let l;
  if (t == e.display.lineDiv) {
    if (l = e.display.lineDiv.childNodes[i], !l)
      return et(e.clipPos(x(e.display.viewTo - 1)), !0);
    t = null, i = 0;
  } else
    for (l = t; ; l = l.parentNode) {
      if (!l || l == e.display.lineDiv)
        return null;
      if (l.parentNode && l.parentNode == e.display.lineDiv)
        break;
    }
  for (let r = 0; r < e.display.view.length; r++) {
    let n = e.display.view[r];
    if (n.node == l)
      return za(n, t, i);
  }
}
function za(e, t, i) {
  let l = e.text.firstChild, r = !1;
  if (!t || !Ae(l, t))
    return et(x(W(e.line), 0), !0);
  if (t == l && (r = !0, t = l.childNodes[i], i = 0, !t)) {
    let h = e.rest ? O(e.rest) : e.line;
    return et(x(W(h), h.text.length), r);
  }
  let n = t.nodeType == 3 ? t : null, s = t;
  for (!n && t.childNodes.length == 1 && t.firstChild.nodeType == 3 && (n = t.firstChild, i && (i = n.nodeValue.length)); s.parentNode != l; )
    s = s.parentNode;
  let o = e.measure, a = o.maps;
  function u(h, d, c) {
    for (let p = -1; p < (a ? a.length : 0); p++) {
      let m = p < 0 ? o.map : a[p];
      for (let g = 0; g < m.length; g += 3) {
        let b = m[g + 2];
        if (b == h || b == d) {
          let y = W(p < 0 ? e.line : e.rest[p]), L = m[g] + c;
          return (c < 0 || b != h) && (L = m[g + (c ? 1 : 0)]), x(y, L);
        }
      }
    }
  }
  let f = u(n, s, i);
  if (f)
    return et(f, r);
  for (let h = s.nextSibling, d = n ? n.nodeValue.length - i : 0; h; h = h.nextSibling) {
    if (f = u(h, h.firstChild, 0), f)
      return et(x(f.line, f.ch - d), r);
    d += h.textContent.length;
  }
  for (let h = s.previousSibling, d = i; h; h = h.previousSibling) {
    if (f = u(h, h.firstChild, -1), f)
      return et(x(f.line, f.ch + d), r);
    d += h.textContent.length;
  }
}
class Cs {
  constructor(t) {
    this.cm = t, this.prevInput = "", this.pollingFast = !1, this.polling = new ft(), this.hasSelection = !1, this.composing = null;
  }
  init(t) {
    let i = this, l = this.cm;
    this.createField(t);
    const r = this.textarea;
    t.wrapper.insertBefore(this.wrapper, t.wrapper.firstChild), Qt && (r.style.width = "0px"), S(r, "input", () => {
      N && F >= 9 && this.hasSelection && (this.hasSelection = null), i.poll();
    }), S(r, "paste", (s) => {
      R(l, s) || ys(s, l) || (l.state.pasteIncoming = +/* @__PURE__ */ new Date(), i.fastPoll());
    });
    function n(s) {
      if (!R(l, s)) {
        if (l.somethingSelected())
          Li({ lineWise: !1, text: l.getSelections() });
        else if (l.options.lineWiseCopyCut) {
          let o = bs(l);
          Li({ lineWise: !0, text: o.text }), s.type == "cut" ? l.setSelections(o.ranges, null, ce) : (i.prevInput = "", r.value = o.text.join(`
`), Rt(r));
        } else
          return;
        s.type == "cut" && (l.state.cutIncoming = +/* @__PURE__ */ new Date());
      }
    }
    S(r, "cut", n), S(r, "copy", n), S(t.scroller, "paste", (s) => {
      if (Se(t, s) || R(l, s))
        return;
      if (!r.dispatchEvent) {
        l.state.pasteIncoming = +/* @__PURE__ */ new Date(), i.focus();
        return;
      }
      const o = new Event("paste");
      o.clipboardData = s.clipboardData, r.dispatchEvent(o);
    }), S(t.lineSpace, "selectstart", (s) => {
      Se(t, s) || j(s);
    }), S(r, "compositionstart", () => {
      let s = l.getCursor("from");
      i.composing && i.composing.range.clear(), i.composing = {
        start: s,
        range: l.markText(s, l.getCursor("to"), { className: "CodeMirror-composing" })
      };
    }), S(r, "compositionend", () => {
      i.composing && (i.poll(), i.composing.range.clear(), i.composing = null);
    });
  }
  createField(t) {
    this.wrapper = ws(), this.textarea = this.wrapper.firstChild;
  }
  screenReaderLabelChanged(t) {
    t ? this.textarea.setAttribute("aria-label", t) : this.textarea.removeAttribute("aria-label");
  }
  prepareSelection() {
    let t = this.cm, i = t.display, l = t.doc, r = Dn(t);
    if (t.options.moveInputWithCursor) {
      let n = ae(t, l.sel.primary().head, "div"), s = i.wrapper.getBoundingClientRect(), o = i.lineDiv.getBoundingClientRect();
      r.teTop = Math.max(0, Math.min(
        i.wrapper.clientHeight - 10,
        n.top + o.top - s.top
      )), r.teLeft = Math.max(0, Math.min(
        i.wrapper.clientWidth - 10,
        n.left + o.left - s.left
      ));
    }
    return r;
  }
  showSelection(t) {
    let i = this.cm, l = i.display;
    ie(l.cursorDiv, t.cursors), ie(l.selectionDiv, t.selection), t.teTop != null && (this.wrapper.style.top = t.teTop + "px", this.wrapper.style.left = t.teLeft + "px");
  }
  // Reset the input to correspond to the selection (or to be empty,
  // when not typing and nothing is selected)
  reset(t) {
    if (this.contextMenuPending || this.composing)
      return;
    let i = this.cm;
    if (i.somethingSelected()) {
      this.prevInput = "";
      let l = i.getSelection();
      this.textarea.value = l, i.state.focused && Rt(this.textarea), N && F >= 9 && (this.hasSelection = l);
    } else
      t || (this.prevInput = this.textarea.value = "", N && F >= 9 && (this.hasSelection = null));
  }
  getField() {
    return this.textarea;
  }
  supportsTouch() {
    return !1;
  }
  focus() {
    if (this.cm.options.readOnly != "nocursor" && (!It || re() != this.textarea))
      try {
        this.textarea.focus();
      } catch {
      }
  }
  blur() {
    this.textarea.blur();
  }
  resetPosition() {
    this.wrapper.style.top = this.wrapper.style.left = 0;
  }
  receivedFocus() {
    this.slowPoll();
  }
  // Poll for input changes, using the normal rate of polling. This
  // runs as long as the editor is focused.
  slowPoll() {
    this.pollingFast || this.polling.set(this.cm.options.pollInterval, () => {
      this.poll(), this.cm.state.focused && this.slowPoll();
    });
  }
  // When an event has just come in that is likely to add or change
  // something in the input textarea, we poll faster, to ensure that
  // the change appears on the screen quickly.
  fastPoll() {
    let t = !1, i = this;
    i.pollingFast = !0;
    function l() {
      !i.poll() && !t ? (t = !0, i.polling.set(60, l)) : (i.pollingFast = !1, i.slowPoll());
    }
    i.polling.set(20, l);
  }
  // Read input from the textarea, and update the document to match.
  // When something is selected, it is present in the textarea, and
  // selected (unless it is huge, in which case a placeholder is
  // used). When nothing is selected, the cursor sits after previously
  // seen text (can be empty), which is stored in prevInput (we must
  // not reset the textarea when typing, because that breaks IME).
  poll() {
    let t = this.cm, i = this.textarea, l = this.prevInput;
    if (this.contextMenuPending || !t.state.focused || Es(i) && !l && !this.composing || t.isReadOnly() || t.options.disableInput || t.state.keySeq)
      return !1;
    let r = i.value;
    if (r == l && !t.somethingSelected())
      return !1;
    if (N && F >= 9 && this.hasSelection === r || ne && /[\uf700-\uf7ff]/.test(r))
      return t.display.input.reset(), !1;
    if (t.doc.sel == t.display.selForContextMenu) {
      let o = r.charCodeAt(0);
      if (o == 8203 && !l && (l = "​"), o == 8666)
        return this.reset(), this.cm.execCommand("undo");
    }
    let n = 0, s = Math.min(l.length, r.length);
    for (; n < s && l.charCodeAt(n) == r.charCodeAt(n); )
      ++n;
    return J(t, () => {
      ir(
        t,
        r.slice(n),
        l.length - n,
        null,
        this.composing ? "*compose" : null
      ), r.length > 1e3 || r.indexOf(`
`) > -1 ? i.value = this.prevInput = "" : this.prevInput = r, this.composing && (this.composing.range.clear(), this.composing.range = t.markText(
        this.composing.start,
        t.getCursor("to"),
        { className: "CodeMirror-composing" }
      ));
    }), !0;
  }
  ensurePolled() {
    this.pollingFast && this.poll() && (this.pollingFast = !1);
  }
  onKeyPress() {
    N && F >= 9 && (this.hasSelection = null), this.fastPoll();
  }
  onContextMenu(t) {
    let i = this, l = i.cm, r = l.display, n = i.textarea;
    i.contextMenuPending && i.contextMenuPending();
    let s = Ke(l, t), o = r.scroller.scrollTop;
    if (!s || fe)
      return;
    l.options.resetSelectionOnContextMenu && l.doc.sel.contains(s) == -1 && B(l, U)(l.doc, Oe(s), ce);
    let u = n.style.cssText, f = i.wrapper.style.cssText, h = i.wrapper.offsetParent.getBoundingClientRect();
    i.wrapper.style.cssText = "position: static", n.style.cssText = `position: absolute; width: 30px; height: 30px;
      top: ${t.clientY - h.top - 5}px; left: ${t.clientX - h.left - 5}px;
      z-index: 1000; background: ${N ? "rgba(255, 255, 255, .05)" : "transparent"};
      outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);`;
    let d;
    $ && (d = window.scrollY), r.input.focus(), $ && window.scrollTo(null, d), r.input.reset(), l.somethingSelected() || (n.value = i.prevInput = " "), i.contextMenuPending = p, r.selForContextMenu = l.doc.sel, clearTimeout(r.detectingSelectAll);
    function c() {
      if (n.selectionStart != null) {
        let m = l.somethingSelected(), g = "​" + (m ? n.value : "");
        n.value = "⇚", n.value = g, i.prevInput = m ? "" : "​", n.selectionStart = 1, n.selectionEnd = g.length, r.selForContextMenu = l.doc.sel;
      }
    }
    function p() {
      if (i.contextMenuPending == p && (i.contextMenuPending = !1, i.wrapper.style.cssText = f, n.style.cssText = u, N && F < 9 && r.scrollbars.setScrollTop(r.scroller.scrollTop = o), n.selectionStart != null)) {
        (!N || N && F < 9) && c();
        let m = 0, g = () => {
          r.selForContextMenu == l.doc.sel && n.selectionStart == 0 && n.selectionEnd > 0 && i.prevInput == "​" ? B(l, Jn)(l) : m++ < 10 ? r.detectingSelectAll = setTimeout(g, 500) : (r.selForContextMenu = null, r.input.reset());
        };
        r.detectingSelectAll = setTimeout(g, 200);
      }
    }
    if (N && F >= 9 && c(), gl) {
      Gt(t);
      let m = () => {
        te(window, "mouseup", m), setTimeout(p, 20);
      };
      S(window, "mouseup", m);
    } else
      setTimeout(p, 50);
  }
  readOnlyChanged(t) {
    t || this.reset(), this.textarea.disabled = t == "nocursor", this.textarea.readOnly = !!t;
  }
  setUneditable() {
  }
}
Cs.prototype.needsContentAttribute = !1;
function Ga(e, t) {
  if (t = t ? Ue(t) : {}, t.value = e.value, !t.tabindex && e.tabIndex && (t.tabindex = e.tabIndex), !t.placeholder && e.placeholder && (t.placeholder = e.placeholder), t.autofocus == null) {
    let n = re();
    t.autofocus = n == e || e.getAttribute("autofocus") != null && n == document.body;
  }
  function i() {
    e.value = r.getValue();
  }
  let l;
  if (e.form && (S(e.form, "submit", i), !t.leaveSubmitMethodAlone)) {
    let n = e.form;
    l = n.submit;
    try {
      let s = n.submit = () => {
        i(), n.submit = l, n.submit(), n.submit = s;
      };
    } catch {
    }
  }
  t.finishInit = (n) => {
    n.save = i, n.getTextArea = () => e, n.toTextArea = () => {
      n.toTextArea = isNaN, i(), e.parentNode.removeChild(n.getWrapperElement()), e.style.display = "", e.form && (te(e.form, "submit", i), !t.leaveSubmitMethodAlone && typeof e.form.submit == "function" && (e.form.submit = l));
    };
  }, e.style.display = "none";
  let r = P(
    (n) => e.parentNode.insertBefore(n, e.nextSibling),
    t
  );
  return r;
}
function Ua(e) {
  e.off = te, e.on = S, e.wheelEventPixels = qo, e.Doc = Y, e.splitLines = wl, e.countColumn = le, e.findColumn = Qi, e.isWordChar = Ji, e.Pass = Ai, e.signal = E, e.Line = _t, e.changeEnd = We, e.scrollbarModel = Pn, e.Pos = x, e.cmpPos = T, e.modes = vl, e.mimeModes = tt, e.resolveMode = pi, e.getMode = Cl, e.modeExtensions = nt, e.extendMode = Gs, e.copyState = Be, e.startState = en, e.innerMode = Sl, e.commands = Zt, e.keyMap = xe, e.keyName = ss, e.isModifierKey = rs, e.lookupKey = at, e.normalizeKeyMap = ma, e.StringStream = Oi, e.SharedTextMarker = Vl, e.TextMarker = Jl, e.LineWidget = Ql, e.e_preventDefault = j, e.e_stopPropagation = Jr, e.e_stop = Gt, e.addClass = $e, e.contains = Ae, e.rmClass = Xe, e.keyNames = He;
}
Ha(P);
Ia(P);
let Ka = "iter insert remove copy getEditor constructor".split(" ");
for (let e in Y.prototype)
  Y.prototype.hasOwnProperty(e) && K(Ka, e) < 0 && (P.prototype[e] = function(t) {
    return function() {
      return t.apply(this.doc, arguments);
    };
  }(Y.prototype[e]));
gt(Y);
P.inputStyles = { textarea: Cs, contenteditable: vs };
P.defineMode = function(e) {
  !P.defaults.mode && e != "null" && (P.defaults.mode = e), Bs.apply(this, arguments);
};
P.defineMIME = zs;
P.defineMode("null", () => ({ token: (e) => e.skipToEnd() }));
P.defineMIME("text/plain", "null");
P.defineExtension = (e, t) => {
  P.prototype[e] = t;
};
P.defineDocExtension = (e, t) => {
  Y.prototype[e] = t;
};
P.fromTextArea = Ga;
Ua(P);
P.version = "5.63.1";
window.CodeMirror = P;
export {
  P as default
};
